Powershell posh ssh:如何存储调用SSHCommand的结果?

Powershell posh ssh:如何存储调用SSHCommand的结果?,powershell,ssh,Powershell,Ssh,关闭连接后,如何存储调用SSHCommand的结果以供使用 我尝试了两种不同的方法: #method 1 $result = Invoke-SSHCommand -Index 0 -Command "ls /somepath" #method 2 Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable $result 变量$result在两种方法之后都是空的这对我来说很有效: # Create SSH Session $

关闭连接后,如何存储调用SSHCommand的
结果以供使用

我尝试了两种不同的方法:

#method 1
$result = Invoke-SSHCommand -Index 0 -Command "ls /somepath"

#method 2
Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable $result

变量
$result
在两种方法之后都是空的

这对我来说很有效:

# 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")

这对我很有用:

#method 1
$CurrentSession=New-SSHSession -ComputerName x.x.x.x -Credential (Get-Credential) 
$result = Invoke-SSHCommand -SSHSession $CurrentSession -Command "ls /somepath"
$result.Output

-OutVariable$result
中删除
$
,它应该可以工作

调用SSHCommand-索引0-命令“ls/somepath”-输出变量结果


正在处理命令中的
$result
,返回null,然后尝试将Invoke SSHCommand的结果输出为null(据我所知)

您是否尝试过以下操作:
Invoke SSHCommand-Index 0-command“ls/somepath”2>&1
我很乐意帮助@Adam.)最后应该是$result,而不是不是PS上不是var名称的“result”。