Lew Nix
asked on
Using Plink with Windows Powershell - Getting redirected STDIN from file
I am trying to run plink from a powershell script. The issue is the commands that need to be run within plink are coming from a file. If I run from a command prompt plink with the appropriate parameters and use < name of file that contains commands, it executes perfectly. I can't seem to get the "<" redirect to work with the plink call in a powershell script. Any suggestions?
Can you post the commands you have?
ASKER
Here is what I am trying to get to execute from a powershell script -
plink.exe -ssh -P 4118 -batch -pw passwordformyrouter -l admin 192.168.0.1 <linkup.txt
The commands that I am actually trying to run on the router/firewall through this plink session are in the linkup.txt file. If I run this from a Windows Command Prompt, it recognizes the < redirection of StdIn to the file and accepts the commands from this text file. I can find a way to get this entire string to be properly executed in PowerShell. I have tried making the parameters a text variable and several other formatting options. PowerShell just doesn't like the < (less than sign).
Does this make sense? If there is a better way, I am open to suggestions.
plink.exe -ssh -P 4118 -batch -pw passwordformyrouter -l admin 192.168.0.1 <linkup.txt
The commands that I am actually trying to run on the router/firewall through this plink session are in the linkup.txt file. If I run this from a Windows Command Prompt, it recognizes the < redirection of StdIn to the file and accepts the commands from this text file. I can find a way to get this entire string to be properly executed in PowerShell. I have tried making the parameters a text variable and several other formatting options. PowerShell just doesn't like the < (less than sign).
Does this make sense? If there is a better way, I am open to suggestions.
Have you tried putting quotes around the argumenents?
Does it have to be a powershell file? Can you just do it in a DOS batch file?
Does it have to be a powershell file? Can you just do it in a DOS batch file?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This Get-Content worked perfectly. Still might have a few kinks to work out in calling it properly in PowerShell, but it is definitely passing the commands through to the session running through plink.
Thank you!!
Thank you!!