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?
Lew NixAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MazdajaiCommented:
Can you post the commands you have?
0
Lew NixAuthor Commented:
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.
0
serialbandCommented:
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?
0
oBdACommented:
Try it like this (adjust the paths for the input file and the exe as required);
Get-Content "C:\Temp\linkup.txt" | & "C:\Program Files\Acme\plink.exe" -ssh -P 4118 -batch -pw passwordformyrouter -l admin 192.168.0.1

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lew NixAuthor Commented:
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!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.