Parameter Syntax Invoke-command -ArgumentList

I am trying to add several imported csv lists to a remote executable PS script. It works fine when I pass only one list using the following command:

Invoke-Command -filepath $createSAPSPath -ConnectionUri $uri -Credential $credential -ArgumentList (,$accountsList)

What will be the correct syntax for multiple list objects? I tried:

Invoke-Command -filepath $createSAPSPath -ConnectionUri $uri -Credential $credential -ArgumentList (,$accountsList),(,$groupsList)

But it does not work ...

Thank,

Glenn

+4
source share
2 answers

You must understand why you need a unary comma in the first situation in order to understand why it is not needed in the second.

-ArgumentList Object[]. , PowerShell ( ) , .

, (, $AnyObject, $EvenCollection), , PowerShell , : , .

: :

Invoke-Command -filepath $createSAPSPath -ConnectionUri $uri -Credential $credential -ArgumentList $accountsList, $groupList

... .

+7

:

$AccountList = 'Account1','Account2'
$GroupList    = 'Group1','Group2'

invoke-command {$args[0];'*****';$args[1]} -ArgumentList (,$AccountList,$GroupList) 

Account1
Account2
*****
Group1
Group2
+3

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


All Articles