简体   繁体   English

使用 PLINK 和 Powershell 的 SSH 连接和命令

[英]SSH Connection & Commands using PLINK with Powershell

I'm trying to create a simple script which run a command and send the output to a variable.我正在尝试创建一个简单的脚本,该脚本运行命令并将输出发送到变量。 this is the script:这是脚本:

$output = &"<Path to PLINK>\PLINK.exe" -ssh <username>@<IP Address> -pw <password> "my command"

the thing is the command im running is like "top" in linux - a task manager which won't quit until enter is being pressed.问题是我正在运行的命令就像 linux 中的“top” - 一个任务管理器,在按下 Enter 之前不会退出。

how can i take the CLI output from that situation without touching my keyboard?如何在不触摸键盘的情况下从这种情况获取 CLI 输出?

i wrote an automation with opening cmd and sending "keys" function inorder to get what i want but i cannot get the output from the CLI by doing so.我写了一个自动化,打开 cmd 并发送“密钥”功能以获得我想要的东西,但我无法通过这样做从 CLI 获得输出。 (also i dont beleive its the right way.) (我也不相信它是正确的方式。)

Thanks in advance.提前致谢。

As I saw in the following page: Run As Admin正如我在以下页面中看到的:以管理员身份运行

using the following code will run the programm PLINK.EXE for you.使用以下代码将为您运行程序 PLINK.EXE。

$Username = 'Username'
$Password = 'Password'
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($Username,$SecurePassword)

Start-Process powershell.exe  -Credential $Credential -NoNewWindow -ArgumentList "(Start-Process -FilePath '\\some\path\app.exe' -ArgumentList  '/q).ExitCode"

我通过为 Powershell 安装 POSH-SSH 模块解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM