Link to home
Start Free TrialLog in
Avatar of McThump
McThump

asked on

Executing external program with PowerShell

I need a PowerShell script to (among other things) execute commands (contained in script.txt) on a remote system.  The following works if I put it in a Windows command file (.cmd).  

C:\PuTTY\plink.exe 10.10.10.5 -ssh -P 1234 -l username -pw xyz < %temp%\script.txt

How can I do this inline in PoweShell?  I expect I'll need to use the invoke-expression comdlet, but can't figure out how to handle the parameters and input redirection.
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this:

$arg1 = "10.10.10.5"
$arg2 = "-ssh"
$arg3 = "-P"
$arg4 = "1234"
$arg5 = "-l"
$arg6="username"
$arg7="-pw"
$arg8 = "xyz"
$arg9="< %temp%\script.txt"

$args = @($arg1,$arg2,$arg3,$arg4,$arg5,$arg6,$arg7,$arg8,$arg9)

 & "C:\PuTTY\plink.exe"  $args
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of McThump
McThump

ASKER

Works perfectly.  Thanks!!