Reputation: 45
I'm totally new to PowerShell. All I'm trying to do is call an .exe on a remote computer using named parameters.
$arguments = "-clientId TX7283 -batch Batch82Y7"
invoke-command -computername FRB-TER1 { Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $arguments}
I get this error.
A parameter cannot be found that matches parameter name 'ArgumemtList'.
+ CategoryInfo: InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound, Microsoft.PowerShell.Commands.StartProcessCommand
+ PSComputerName : FRB-TER1
ArgumentList probably doesn't like parameter names. Not sure.
Upvotes: 2
Views: 7114
Reputation: 9123
This should do your work:
$arguments = "-clientId TX7283 -batch Batch82Y7"
invoke-command -computername FRB-TER1 {param($arguments) Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumentList $arguments} -ArgumentList $arguments
Upvotes: 3
Reputation:
To pass a local variable to a scriptblock executed remotely you can also use $Using:Varname
(from Posh Version 3.0 on). See the help of Invoke-Command
:
> help Invoke-Command -Full |Select-String -Pattern '\$using' -Context 1,7
PS C:\> Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog
> -LogName $Using:MWFO_Log -Newest 10}
This example shows how to include the values of local variables in a
command run on a remote computer. The command uses the Using scope
modifier to identify a local variable in a remote command. By default, all
variables are assumed to be defined in the remote session. The Using scope
modifier was introduced in Windows PowerShell 3.0. For more information
about the Using scope modifier, see about_Remote_Variables
$using:varname
See this reference So this should work too (untested)
$arguments = "-clientId TX7283 -batch Batch82Y7"
Invoke-Command -computername FRB-TER1 {Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" $Using:arguments}
Upvotes: 0
Reputation: 11254
Try this one:
# Lets store each cmd parameter in an array
$arguments = @()
$arguments += "-clientId TX7283"
$arguments += "-batch Batch82Y7"
invoke-command -computername FRB-TER1 {
param (
[string[]]
$receivedArguments
)
# Start-Process now receives an array with arguments
Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $receivedArguments
} -ArgumentList @(,$arguments) # Ensure that PS passes $arguments as array
Upvotes: 0