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

Extra characters in stream output

Open SunsparcSolaris opened this issue 1 year ago • 3 comments

Getting extra character output like this from stream against an HPE switch (Cisco style, so Invoke-SSHCommand not working):

[1;13r[1;1H[24;1HPress any key to continue[13;1H[?25h[24;27H[?6l[1;24r[?7h[2J[1;1H[1920;1920H[6n[1;1HYour previous successful login (as operator) was on 2024-04-04 14:23:37

Here's my code:

Try {
		$connection = New-SSHSession -ComputerName $switch -Credential $Cred -AcceptKey:$True -ErrorAction Stop
		Write-Host "$switch SSH Session created" 
	} Catch {
		Write-Host "$switch Error creating SSH Session" -Foregroundcolor Red -Backgroundcolor Black
		$ErrorSwitches += [PSCustomObject] @{
			Switch = $Switch
			Error = $error[0].Exception.Message
		}
		Continue
	}
	$session = Get-SSHSession -ComputerName $switch
	$stream = New-SSHShellStream -Index 0
	Write-Host "$switch Starting backup"
	$sshCommand = @"
A
en
USERNAME
PASSWORD
copy startup-config $backupPath $configFile 
Logout
Y
Y
"@
$streamoutput = Invoke-SSHStreamShellCommand -ShellStream $stream -Command $sshCommand
Start-Sleep -Seconds 2
$streamoutput | Out-File $logFile

SunsparcSolaris avatar Apr 04 '24 18:04 SunsparcSolaris

That may be ASCII color characters. Try it in a terminal that can display them like the terminal app in Windows 11 or the terminal app from the windows store.

darkoperator avatar Apr 04 '24 19:04 darkoperator

That may be ASCII color characters. Try it in a terminal that can display them like the terminal app in Windows 11 or the terminal app from the windows store.

I use color-capable PuTTY normally and it is not showing that there is color being displayed.

SunsparcSolaris avatar Apr 04 '24 19:04 SunsparcSolaris

Those are ANSI escape codes. Noticed a similar issue with Netmiko and some HP switches. You will need to strip those out, no clue if changing the session encoding would male a difference since I dont have access to that type of gear

darkoperator avatar Apr 04 '24 20:04 darkoperator