Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArgumentList parameter in Invoke-Command don't send all array

First short code, then 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 Write-Host in Invoke-Command block give only this output ?

Service1

Thanks for any answers

like image 290
Zabaa Avatar asked Sep 11 '13 14:09

Zabaa


1 Answers

You solution is to pass it like (,$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

possible explanation from this SO answer.

like image 80
Mitul Avatar answered Nov 15 '22 22:11

Mitul