Posh-Cisco icon indicating copy to clipboard operation
Posh-Cisco copied to clipboard

Exception calling "EndExecute" with "1" argument(s): "An established connection was aborted by the server."

Open mc1903 opened this issue 6 years ago • 11 comments

I get this error with every command I try to execute against a Cisco Catalyst 3560G switch.

image

Posh-Cisco version 1.0.3 Posh-SSH version 2.0.2 PowerShell version 5.1.17134.228

What version(s) of Posh-SSH has Posh-Cisco been successfully tested with?

Thanks mc1903

mc1903 avatar Sep 08 '18 11:09 mc1903

I found it works using Posh-SSH version 1.7.7

The Posh-Cisco install automatically installs the latest version of Posh-SSH as a dependency. So either install Posh-SSH version 1.7.7 BEFORE installing Posh-Cisco or uninstall Posh-SSH version 2.x AFTER manually installing Posh-SSH version 1.7.7.

Install-Module -Name Posh-SSH -RequiredVersion 1.7.7

or

Uninstall-Module -Name Posh-SSH -RequiredVersion 2.0.2

mc1903 avatar Sep 08 '18 12:09 mc1903

Still fails with the new Posh-SSH 2.1. Same error, different line in Posh-SSH.psm1

image

I now need to have both Posh-SSH version 1.7.7 & 2.1 installed; so I am using the following #requires statement in my scripts that are still the Posh-Cisco 1.0.3 Cmdlets:

#requires -Module @{ModuleName="Posh-SSH";RequiredVersion="1.7.7"},@{ModuleName="Posh-Cisco";ModuleVersion="1.0.3"}

Enjoy.

mc1903 avatar Jan 25 '19 23:01 mc1903

I made the following change to the Get-CiscoSSHResponse and it seems to work now.

`function Get-CiscoSSHResponse { [OutputType([String])] param ( [Parameter(Mandatory=$true)] [String]$HostAddress , [Parameter(Mandatory=$false)] [Int]$HostPort = 22, [Parameter(Mandatory=$true)] [PSCredential]$Credential, [Parameter(Mandatory=$false)] [Switch]$AcceptKey, [Parameter(Mandatory=$true)] [String]$Command, [Parameter(Mandatory=$false)] [String]$StripHeaderAt = $null )

$SSHSession = New-SSHSession -ComputerName $HostAddress -Port $HostPort -Credential $Credential -AcceptKey:$AcceptKey;
$SSHResponse = New-SSHShellStream -SessionId $SSHSession.SessionId
   
if ($SSHSession.Connected)
{
    $SSHResponse = Invoke-SSHStreamShellCommand -ShellStream $SSHResponse -Command $Command;

    $SSHSessionRemoveResult = Remove-SSHSession -SSHSession $SSHSession;

    if (-Not $SSHSessionRemoveResult)
    {
        Write-Error "Could not remove SSH Session $($SSHSession.SessionId):$($SSHSession.Host).";
    }

    $Result = $SSHResponse | Out-String;

    $StartIndex = 0;

    if ($StripHeaderAt)
    {
        $StartIndex = $Result.IndexOf("`n$StripHeaderAt") + 1;
    }

    return $Result.Substring($StartIndex).Replace("`r`n","`n").Trim();
}
else
{
    throw [System.InvalidOperationException]"Could not connect to SSH host: $($HostAddress):$HostPort.";
}

$SSHSessionRemoveResult = Remove-SSHSession -SSHSession $SSHSession;

if (-Not $SSHSessionRemoveResult)
{
    Write-Error "Could not remove SSH Session $($SSHSession.SessionId):$($SSHSession.Host).";
}

}`

ShafeeqH avatar Jul 01 '19 15:07 ShafeeqH

I will have a look at this ASAP.

Nevets82 avatar Jul 02 '19 20:07 Nevets82

I am also having this issue. I just installed the module today.

samabenie1 avatar Aug 28 '19 19:08 samabenie1

Any update on this fix? I have tried the solution ShafeeqH posted but it only returns to the first --more-- line then no more output.

koquinn75 avatar Nov 13 '19 14:11 koquinn75

I am also struggling with this on Cisco devices. I have also tried to follow the workaround to no-avail.

Tom-Whi avatar Feb 02 '20 20:02 Tom-Whi

I would like to see a fix as well

bryceismad1 avatar Feb 05 '20 07:02 bryceismad1

Any update?

oyvindlw avatar Feb 05 '20 11:02 oyvindlw

Use the 'terminal length 0' command as the first command after you login. You should get full outputs instead of any breaks and 'more' prompts for the current session.

And another option for connecting to Cisco devices if you don't want to modify the Posh-SSH functions is configure the session as a console stream, as the article below shows. This also works for comware and provision. https://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/

barky11 avatar Feb 05 '20 17:02 barky11

Running Posh-Cisco v3.0.8 and still getting exactly the same exception when trying to get running-config from a Cisco Catalyst. Have tried updating Get-CiscoSSHResponse according to shafeeqH. But that dont work either. All our Nexus switches works fine, just not our Catalysts. :( Any news?

maekee avatar Apr 20 '23 15:04 maekee