I am trying to use the powershell call operator to essentially run the following command:

"C:\Program Files (x86)\PuTTY\plink.exe" "-v -agent -m C:\Scripts\idrac_powerup_commands.txt root@[servername]"

Current Code

$runputtyscript = @()
$runputtyscript += "-v"
$runputtyscript += "-agent"
$runputtyscript += "-m C:\Scripts\idrac_powerup_commands.txt"

& 'C:\Program Files (x86)\PuTTY\plink.exe' $allArgs root@servername


This executes, but the script doesn't execute the file with the commands the same that it does if the original string was executed from the command line.. It shows me the admin console (so it has logged in, authenticated with the public key, etc.) but it just hasn't run the script I asked it to run.

Things I've tried

  • Moving the filename component of -m to its own argument
  • Putting quotes around the filename component of -m


Maybe more succinct way of asking: What is the proper way to use arguments that then have their own arguments (e.g. "-m [filename] -v -a" with the call operator (&) in powershell?


You may be running into the case where your variable is not being handled by the Win32 binary. You can ease this along through double-quotes:

'C:\Program Files (x86)\PuTTY\plink.exe' "$allArgs" root@servername

I had the same problem with netsh a while back.

  • Interestingly enough, that didn't fix it, but writing out the entire string does...from the command line. See my answer. It works for the console, and when I call powershell.exe C:\Scripts\script.ps1 but doesn't work from a scheduled task (which I think is a separate problem) Feb 8 '13 at 13:07

For some reason, writing it in the following way causes it to work perfectly from a powershell prompt, and from a command prompt calling powershell.exe C:\Path\To\Script.ps1

& 'C:\Program Files (x86)\PuTTY\plink.exe' -v -agent -m C:\Scripts\idrac_powerup_commands.txt root@servername | Write-Host

Go figure.


You almost had it. Each parameter has to be a seperate array element. ($allargs ?)

$runputtyscript = @()
$runputtyscript += "-v"
$runputtyscript += "-agent"
$runputtyscript += "-m"
$runputtyscript += "C:\Scripts\idrac_powerup_commands.txt"

& 'C:\Program Files (x86)\PuTTY\plink.exe' $runputtyscript root@servername

I would add it to the path and run it directly:

$env:path += ';C:\Program Files (x86)\PuTTY'
plink -v -agent -m C:\Scripts\idrac_powerup_commands.txt root@servername

Or without changing the path, backquote the space without using quotes:

C:\Program` Files` (x86)\PuTTY\plink.exe -v -agent -m C:\Scripts\idrac_powerup_commands.txt root@servername

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.