开发者

Send data to putty in powershell

开发者 https://www.devze.com 2023-01-15 22:55 出处:网络
I have powershell script that open putty.exe in process and i want to send data to this process, how can i do that???

I have powershell script that open putty.exe in process and i want to send data to this process, how can i do that??? PLEASE HELP!

The process:

$solExe = [diagnostics.process]::start("putty.e开发者_如何学JAVAxe", "-raw -P 2000 127.0.0.1")


The command line interface for putty is plink.exe. You can use plink to send commands over ssh.

For example: PS C:> c:\progra~2\putty\plink.exe -i C:\credentials\mykeyfile.ppk root@myserver.com "ls";

Things to remember:

The first time you connect to a server, you'll have to add it to your registry, so this won't work in a non-interactive mode for brand new servers. There isn't a way to disable this.

The key file has to be in ppk format for plink.exe to recognize it. If yours is in pem format, use puttygen.exe to create a ppk file.

The path to the key file cannot contain any spaces, or the command above won't work.

If you want to send multiple commands at once, write them to a file and use the -m switch with plink.exe.

If you need to transfer files, you can use pscp.exe in a similar fashion.

0

精彩评论

暂无评论...
验证码 换一张
取 消