[英]Powershell posh-ssh: How to store results of Invoke-SSHCommand?
How can I store the result of Invoke-SSHCommand
for use after I close the connection? 在关闭连接后,如何存储Invoke-SSHCommand
的结果?
I've tried 2 different ways: 我尝试了两种不同的方式:
#method 1
$result = Invoke-SSHCommand -Index 0 -Command "ls /somepath"
#method 2
Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable $result
The variable $result
is empty after both methods 两种方法后,变量$result
为空
This worked well for me : 这对我很有用:
# Create SSH Session
$ssh = New-SSHSession -ComputerName $PC01 -Credential $credential -AcceptKey 1
# Invoke SSH command and capture output as string (you can return the full object if you like, I just needed the string Out)
$ret = $(Invoke-SSHCommand -SSHSession $ssh -Command "racadm getconfig -g cfgUserAdmin -i 2").Output
# return object is a String - if you want it as an array of strings for each row returned
$ret = $ret.split("`n")
This was working for me: 这对我有用:
#method 1
$CurrentSession=New-SSHSession -ComputerName x.x.x.x -Credential (Get-Credential)
$result = Invoke-SSHCommand -SSHSession $CurrentSession -Command "ls /somepath"
$result.Output
Remove the $
from your -OutVariable $result
and it should work. 从-OutVariable $result
删除$
,它应该可以工作。
Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable result
Your $result
in the command was being processed, returning null, then trying to output the results of Invoke-SSHCommand to null as far as I can tell 正在处理命令中的$result
,返回null,然后尝试将Invoke-SSHCommand的结果输出为null,据我所知
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.