ArgumentList parameter in Invoke-Command does not send the entire array

The first short code, then the question

$session = New-PSSession -ComputerName someServer $servicesList = "Service1", "Service2", "Service3" Invoke-Command -ScriptBlock { Param ($newServicesList) Write-Host $newServicesList } -ArgumentList $servicesList -Session $session Remove-PSSession $session 

The question is, why does Write-Host in the Invoke-Command block give only this output?

 Service1 

Thanks for any answers.

+4
source share
1 answer

You should pass this as (,$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 

a possible explanation from this is SO answer .

+7
source

Source: https://habr.com/ru/post/1501672/


All Articles