Powershell - Pass multiple parameters to Invoke-Command Powershell - Pass multiple parameters to Invoke-Command powershell powershell

Powershell - Pass multiple parameters to Invoke-Command


Use param($val1,...) inside the scriptblock to pass the arguments.

Invoke-Command -ComputerName 'SERVERNAME' -ScriptBlock {param($argument1, $argument2) #<--- this is required! write-host $CCode write-host $Site} -ArgumentList ($argument1, $argument2)

More information and syntax can be found at ArgumentList (alias Args) section for Invoke-Command cmdlet.


You may have an issue with the way you're expanding your variables and hence it may appear the args are not being passed correctly, when I'm debugging I simply use write to test the output. For example:

Invoke-Command -ComputerName localhost -ScriptBlock {write "C:\Program Files\Veritas\NetBackup\bin\admincmd\bpplinfo.exe CC0SITE_VMW_BRON -set -L -M CC0SITEb0100d0a.s0SITE.CC.DOMAIN.com"}Invoke-Command -ComputerName localhost -ScriptBlock {write "C:\Program Files\Veritas\NetBackup\bin\admincmd\bpplinfo.exe $($args[0])0$($args[1])_VMW_BRON -set -L -M $($args[0])0$($args[1])b0100d0a.s0$($args[1]).$($args[0]).DOMAIN.com"} -Args "CC", "SITE"