[英]Powershell posh-ssh: How to store results of Invoke-SSHCommand?
在關閉連接后,如何存儲Invoke-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
刪除$
,它應該可以工作。
Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable result
正在處理命令中的$result
,返回null,然后嘗試將Invoke-SSHCommand的結果輸出為null,據我所知
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.