11

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

$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

感谢您的任何回答

4

1 回答 1

18

您的解决方案是像这样传递它(,$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的可能解释。

于 2013-09-11T14:56:21.037 回答