Author Posts

October 12, 2017 at 7:54 pm

Install-packageprovider -name NuGet -MinimumVersion -force
Install-Module Posh-SSH -Force
$Username = 'User'
$Password = 'Password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
New-SSHSession -Credential $Cred -AcceptKey
Invoke-SSHCommand -Index 0 -Command "show time"
Remove-SSHSession 0
Exception calling "EndExecute" with "1" argument(s): "Command 'show time' has timed out."

I've looked everywhere an I can't seem to find out why I'm running into this error. The ssh command is running on a sonicwall and it isn't prompting the user so it should just run. Hmm, I'm lost.

October 12, 2017 at 9:36 pm

I don't know if 'show time' is valid linux command

This is what I usually use:

Install-Module SB-Tools,POSH-SSH -Force 
$IPv4Address = ''
$Cred = Get-SBCredential -UserName 'User'

$mySession = New-SSHSession -ComputerName $IPv4Address -Credential $Cred -AcceptKey
Invoke-SSHCommand -SessionId $mySession.SessionId -Command 'date'

with output like

Host       :
Output     : {Thu Oct 12 16:35:15 CDT 2017}
ExitStatus : 0

October 13, 2017 at 1:56 am

Thanks for the input, and correct "show time" is not a linux command to my knowledge. this is running on a sonicwall firewall.

October 13, 2017 at 10:39 am

Posh-SSH Author recommend to use SSHStream for exotic devices...

October 13, 2017 at 4:00 pm

This is how I got the streaming part to work from Posh-ssh

              $newSSH = New-Session -ComputerName $address -Credential $Creds -AcceptKey
               If ($newSSH){
                   $SSHSession - Get-Session $newSSH
                   $Global:SSHStream = $SSHSession.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000)
                   Start-Sleep -Milliseconds 500
          Catch [Exception] {

From there you can enter commands like this:

     $SSHStream.WriteLine(“show time”)
     Start-Sleep -Milliseconds 500

October 13, 2017 at 5:15 pm

Thanks for the input! I think this is the right track for sure and this is most likely an easy error to overcome, just cant seem to get past it: "Get-SSHSession : Cannot bind positional parameters because no names were given." Thanks again for the help

if ((get-packageprovider).name -notcontains "NUGet") {Install-packageprovider -name NuGet -MinimumVersion -force}
if ((get-module).name -notcontains "Posh-SSH") {Install-Module Posh-SSH -Force}
$Username = 'User'
$pass = ConvertTo-SecureString -AsPlainText 'Password' -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
$newSSH = (New-SSHSession -Credential $Cred -AcceptKey)
If ($newSSH){
    $SSHSession = Get-SSHSession $newSSH
    $Global:SSHStream = $SSHSession.Session.CreateShellStream("show time", 0, 0, 0, 0, 1000)
    Start-Sleep -Milliseconds 500
} else {Write-Output "No SSH Session"}

October 13, 2017 at 5:24 pm

Not sure if line 7 needs to be in parens. ( )

Possibly this may help, I have it at the start of my function:

   function Start-SSH {
            $RCred = $'Router Logon','Provide Router Username and Password','',''),
            $REnable = $'Router Enable','Provide Enable Password','','')

If you do not use elevated privs, remove the second credentials argument.

Then, simply call $RCred in the New-SSHSession command:

     $newSSH = New-SSHSession -ComputerName $IPAddress -Credential $RCred -AcceptKey

In retrospect I may have opened a whole extra can of worms – you may need to remove the "$syncHash." element
I have a global that sets host

$ = $host

October 16, 2017 at 2:25 pm

Thanks again, no luck. I'm going to try a third part program (pling in this case). to automate the ssh request. Ill update this afterwords.