首页 > 解决方案 > 如何在 Powershell 上捕获 OpenSSH 输出?

问题描述

我在 PowerShell 脚本上使用 OpenSSH SSH 到 FreeBSD 服务器。我回显“Hello”这个词,我想将返回的 Hello 捕获到 PowerShell 变量中。我怎样才能做到这一点?

$ssh = New-Object -ComObject shell.Application;
$ssh = Start-Process -NoNewWindow ssh user@192.168.19.230
$wshell = New-Object -ComObject wscript.shell;
sleep 1
$wshell.SendKeys('echo Hello')
$wshell.SendKeys('{Enter}')

我已经尝试过$output = $wshell.SendKeys('{Enter}'),但它没有得到任何东西。我搜索了将输出捕获到文件的方法,但没有成功。

标签: powershellsshopenssh

解决方案


推荐阅读