Invoke-Command中的ArgumentList参数不发送所有数组

时间:2013-09-11 14:28:08

标签: powershell powershell-v2.0 invoke-command

首先是短代码,然后是问题

$session = New-PSSession -ComputerName someServer

$servicesList = "Service1", "Service2", "Service3"

Invoke-Command -ScriptBlock {
    Param ($newServicesList)

    Write-Host $newServicesList

} -ArgumentList $servicesList -Session $session

Remove-PSSession  $session

问题是为什么Invoke-Command块中的Write-Host只给出了这个输出?

Service1

感谢您的回答

1 个答案:

答案 0 :(得分:11)

您的解决方案是将其传递为(,$servicesList)

$session = New-PSSession -ComputerName .

$servicesList = "Service1", "Service2", "Service3"

Invoke-Command -ScriptBlock {
    Param ([string[]]$newServicesList)

    Write-Host $newServicesList

} -ArgumentList (,$servicesList) -Session $session

Remove-PSSession  $session

SO answer的可能解释。