[英]Declaring arrays in powershell workflows
I need an array of size n in powershell workflow 我在Powershell工作流程中需要一个大小为n的数组
workflow hai{
$arr=@(1,2)
$a=@(0)*$arr.Count #array needed
for ($iterator=0;$iterator -lt $arr.Count;$iterator+=1){
$a[$iterator]=$arr[$iterator]
}
}
This shows error at the line 这显示了错误
$a[$iterator]=$arr[$iterator]
We can use like this 我们可以这样使用
workflow hai{
$arr=@(1,2)
$a=@()
for ($iterator=0;$iterator -lt $arr.Count;$iterator+=1){
$a+=$arr[$iterator]
}
}
But my case is different where I have to access the array using index. 但是我的情况不同,我必须使用索引访问数组。 Is there a way to do this in workflow 有没有办法在工作流程中做到这一点
You get that error because workflow doesn't support assignment to an indexer. 您会收到该错误,因为工作流不支持分配给索引器。 See this article for a number of limitations of workflow. 有关工作流程的许多限制,请参见本文 。 Try using an inlinescript to get what you want eg: 尝试使用内联脚本来获取所需内容,例如:
workflow hai{
$arr = @(1,2)
$a = inlinescript {
$tmpArr = $using:arr
$newArr = @(0)*$tmpArr.Count #array needed
for ($iterator=0;$iterator -lt $newArr.Count;$iterator+=1){
$newArr[$iterator] = $tmpArr[$iterator]
}
$newArr
}
$a
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.