編輯:我在這裏已經改變了代碼,以一個簡單的測試用例,而不是在那裏這個問題所帶來的全面實施。PowerShell腳本參數傳遞的數組
我試圖從另一個調用一個PowerShell腳本,但事情不工作了,我很期待。據我瞭解的東西,在「&」運營商應該擴大陣列分成不同的參數。這不會發生在我身上。
caller.ps1
$scriptfile = ".\callee.ps1"
$scriptargs = @(
"a",
"b",
"c"
)
& $scriptfile $scriptargs
callee.ps1
Param (
[string]$one,
[string]$two,
[string]$three
)
"Parameter one: $one"
"Parameter two: $two"
"Parameter three: $three"
運行.\caller.ps1
結果如下輸出:
Parameter one: a b c
Parameter two:
Parameter three:
我認爲概率LEM我遇到的$scriptargs
數組未展開,並作爲參數傳遞相當。我使用PowerShell的2
我怎樣才能得到caller.ps1與參數數組運行callee.ps1?
我還應該在這裏注意到,我使用了PowerShell社區擴展的EchoArgs實用程序,並且參數顯示爲格式正確。 – Sam
您將部署參數定義爲數組您是否嘗試將該字符串作爲表達式調用 – rerun
我試圖將參數構建爲[本博客文章]上看到的數組(http://edgylogic.com/blog/powershell- and-external-commands-done-right /)標題下的「但是如果我想構建參數來傳遞我的腳本呢?」 – Sam