首先是短代码,然后是问题
$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
感谢您的回答
答案 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的可能解释。