param( [Parameter(Mandatory = $true)][string]$Cmd, [int]$TimeoutSec = 90 ) $ErrorActionPreference = 'Stop' Import-Module Posh-SSH $pw = ConvertTo-SecureString '0' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential('tonycao', $pw) $s = New-SSHSession -ComputerName 192.168.58.7 -Credential $cred -AcceptKey -Force try { $r = Invoke-SSHCommand -SessionId $s.SessionId -Command $Cmd -TimeOut $TimeoutSec foreach ($l in $r.Output) { Write-Host $l } foreach ($l in $r.Error) { Write-Host "STDERR: $l" } Write-Host "EXIT:$($r.ExitStatus)" } finally { Remove-SSHSession -SessionId $s.SessionId | Out-Null }