Nevets82 / Posh-Cisco

PowerShell module that provides some functionality to facilitate automating backup actions of a Cisco device over SSH. This module also provides some basic functionality for troubleshooting Cisco devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

mc1903 opened this issue · 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

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

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.

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).";
}

}`

I will have a look at this ASAP.

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

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.

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

I would like to see a fix as well

Any update?

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/

commented

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?