2017-01-20 9 views
2

Invoke-SSHCommandの結果を、接続を閉じた後にどのように保存することができますか?Powershell posh-ssh:Invoke-SSHCommandの結果を保存するには?

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

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

これは私のためによく働い

+0

を言うことができるようにnullに出力するinvoke-SSHCommandの結果をしようと

コマンドで

Invoke-SSHCommand -Index 0 -Command "ls /somepath" -OutVariable result

あなた$resultがnullを返して、処理されていたが、あなたはこれを試してみました-SSHCommand -Index 0 -Command "ls/somepath" 2>&1' –

答えて

5

変数$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") 
+0

@Adam:あなたが助けてくれれば答えを受け入れてください。 –

+0

多くのおかげで、これは完全に動作します! :) – Adam

+0

@Adamを手伝ってくれて嬉しいです。 :) –

2

これは私のために働いていた

は、私は2種類の方法を試してみました:

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

​​から$を削除しても問題ありません。 `呼び出します。その後、私の知る限り

関連する問題