0
我試圖讓我的腳溼透PowerShell工作流和一些工作,我需要做的並行。問題了解Powershell工作流For Each
我沒有得到很遠,打我的第一個路障前,但我不明白我在做什麼錯在這裏:
$operations = ,("Item0", "Item1")
ForEach ($operation in $operations) {
Write-Output "Item0: $($operation.Item(0)) Item1: $($operation.Item(1))"
}
workflow operationsWorkflow{
Write-Output "Running Workflow"
$operations = ,("Item0", "Item1")
ForEach -Parallel ($operation in $operations) {
#Fails: Method invocation failed because [System.String] does not contain a method named 'Item'.
#Write-Output "Item0: $($operation.Item(0)) Item1: $($operation.Item(1))"
Write-Output "Item $operation"
}
}
operationsWorkflow
到目前爲止,我所能說的是,在這種情況下,逗號技巧並不適用於創建數組。我的第一個猜測是使用.NET'[System.Collections.Generic.List [string []]]'或類似的東西,而不是依靠PowerShell數組魔術。 – Eris
注意:如果'$ operations'有多個數組項添加,即使註釋行也能正常工作。例如:'$ operations = @((「Item0」,「Item1」),(「ItemA」,「ItemB」))' – Eris
我想要PowerShell,我只是總是感到困惑...... –