Invoke-command -ArgumentList parameter syntax

ぃ、小莉子 提交于 2019-12-01 18:23:02

You have to realize why you need unary comma in the first situation, to understand why its not needed in the second one.

Parameter -ArgumentList takes Object[] argument type. If you are passing single collection, you need to prevent PowerShell from treating single argument (that happens to be a collection) as collection of arguments passed to this parameter.

If you pass something that is collection already (e.g. $AnyObject, $EvenCollection), regardless of the type of individual objects, PowerShell will do what users usually expect: pass first collection to first parameter, second collection to the second parameter.

To sum it up: you should be able to run this like that:

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

... and get expected results.

Try it this way:

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

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

Account1
Account2
*****
Group1
Group2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!