darkoperator / Posh-SSH

PowerShell Module for automating tasks on remote systems using SSH
BSD 3-Clause "New" or "Revised" License
983 stars 227 forks source link

Problem with Invoke-SSHCommand #146

Closed AlexandreRenoux closed 7 years ago

AlexandreRenoux commented 7 years ago

hi,

I have a problem :

New-SSHSession -computerName 172.31.0.11

SessionId Host Connected


0      172.31.0.11                                                 True

So, it's co and :

Invoke-SSHCommand -index 0 -Command "conf t"

Exception calling "BeginExecute" with "0" argument(s): "An established connection was aborted by the server." At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\1.7.7\Posh-SSH.psm1:348 char:17

  • $Async = $cmd.BeginExecute()
  • 
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SshConnectionException

I try with 1.7.8, 1.7.7, 1.6 and 1.5 version of Posh-SSH and it don't work :(

Have you got a solution pls?

darkoperator commented 7 years ago

Is this a cisco device?

Sent from my iPhone

On May 16, 2017, at 9:55 AM, AlexandreRenoux notifications@github.com wrote:

hi,

I have a problem :

New-SSHSession -computerName 172.31.0.11 SessionId Host Connected

0 172.31.0.11 True So, it's co and :

Invoke-SSHCommand -index 0 -Command "conf t"

Exception calling "BeginExecute" with "0" argument(s): "An established connection was aborted by the server." At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\1.7.7\Posh-SSH.psm1:348 char:17

        $Async = $cmd.BeginExecute()
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CategoryInfo : NotSpecified: (:) [], MethodInvocationException FullyQualifiedErrorId : SshConnectionException I try with 1.7.8, 1.7.7, 1.6 and 1.5 version of Posh-SSH and it don't work :(

Have you got a solution pls?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

AlexandreRenoux commented 7 years ago

No, it's AVAYA device, we have 2 switch device : HP when posh-ssh run correctly and AVAYA when I have this error.

darkoperator commented 7 years ago

Have you tried a SSHStream instead just like with a cisco device? More than likely the device does not support sshexec like cisco and many others and expect a full terminal to be set first

Sent from my iPhone

On May 16, 2017, at 10:35 AM, AlexandreRenoux notifications@github.com wrote:

No, it's AVAYA device, we have 2 switch device : HP when posh-ssh run correctly and AVAYA when I have this error.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

AlexandreRenoux commented 7 years ago

Yes, with putty it's ok, and it's strange because 1 week later, PoshSSH run on AYAVA device.. and today I have this error

darkoperator commented 7 years ago

Putty creates a terminal. Create a SSHStream and use that instead, a SSHStream behaves like putty C:\PS>$SSHStream = New-SSHShellStream -Index 0 PS C:> $SSHStream.WriteLine("uname -a") PS C:> $SSHStream.read() Last login: Sat Mar 14 20:02:16 2015 from infidel01.darkoperator.com [admin@localhost ~]$ uname -a Linux localhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [admin@localhost ~]$

On May 17, 2017, at 3:33 AM, AlexandreRenoux notifications@github.com wrote:

Yes, with putty it's ok, and it's strange because 1 week later, PoshSSH run on AYAVA device.. and today I have this error

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/146#issuecomment-302009998, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0Hrz_mRUzvbymf9dejSi1tPoKWKh0ks5r6qLBgaJpZM4NciUO.

AlexandreRenoux commented 7 years ago

It works, thank you very much !!!!!!!

dr7u15 commented 2 years ago

I am unable to export or manipulate the output generated by the SSH stream in PowerShell. Say for example, if I run a command like: $SSHStream.read() | out-file c:\test.txt

There is no output. However, if I just run $SSHStream.read(), it does show the output on the PowerShell terminal. Anyone knows why this is the case? Thanks for your time!

MVKozlov commented 2 years ago

try to add timeout before .read()