Powershell posh-ssh: How to store results of Invoke-SSHCommand? Powershell posh-ssh: How to store results of Invoke-SSHCommand? powershell powershell

Powershell posh-ssh: How to store results of Invoke-SSHCommand?


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.

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