How to change the return limit with Invoke-SSHStreamShellCommand
Hello,
I tried using Invoke-SSHStreamShellCommand with ShellStrem, but if I want to get a lot of line feedback such as configuring a switch with the show run command, the feedback is copied after about 14 lines. Is it possible to change this behavior.
Thanks
Can you provide an example? can't figure out what is happening by the description provided. Normally one reads the stream to a point, issues a command, and then reads from that point on.
`$strUser = "SamAcountXXX" $strPasswordPlainText = "XXXXXXXXXXXXXXXXXXXXX" $objPassword = ConvertTo-SecureString -String $strPasswordPlainText -AsPlainText -Force $objAdUser = Get-ADUser -Identity $strUser
$Hostname = 'switch.xxx.local'
$objCredential = New-Object Management.Automation.PSCredential ($objAdUser.SamAccountName, $objPassword) $objSshSession = New-SSHSession -ComputerName $Hostname -Credential $objCredential -AcceptKey $objSshShellStream = New-SSHShellStream -Index $objSshSession.SessionId
[string]$strSshCommands = $null
$strSshCommands = "$($objAdUser.SamAccountName)r" $strSshCommands += "$strPasswordPlainTextr"
$strSshCommands += "show run"
$objSSHStreamShellCommand = Invoke-SSHStreamShellCommand -ShellStream $objSshShellStream -Command $strSshCommands $objSSHStreamShellCommand`
Result : #START
show run terminal datadump Password:
NC1212#config-file-header NC1212 v1.4.11.5 / R800_NIK_1_4_220_026 CLI v1.0 set system mode router
file SSD indicator encrypted @ ssd-control-start ssd config ssd file passphrase control unrestricted no ssd file integrity control ssd-control-end cb0a3fdb1f3a1af4e4430033719968c0 ! #END
Normally the result contains hundreds of rows
Regards
I think it is because it is not recognizing the prompt, since this was written taking into account VyOS and Linux for the prompt. You can change the Regex for what ever cisco device this is, I bet that if you do an additional read on the stream, $objSshShellStream.Read() the rest of the data will be there.
Indeed after using $objSshShellStream.Read() I have more data but at the end the prompt ends with # and is part of the regex so I don't really understand where the problem comes from.
Maybe I should do a $objSshShellStream.Read() until $objSshShellStream.DataAvailable is false and concatenate the contents? I think there is a better way?
fix would be to specify a regex for the device prompt in the parameter, the reason the current one is failing is that in VyOS and Linux there is a space after the prompt symbol and end of line and in cisco there is not
Because the regex expect a space before the end of line? And the Cisco device does not have one. You can use the same regex but remove the space before the $
On May 23, 2022, at 8:28 AM, Xenixium @.***> wrote:
Indeed after using $objSshShellStream.Read() I have more data but at the end the prompt ends with # and is part of the regex so I don't really understand where the problem comes from.
— Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/460#issuecomment-1134612184, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHX4QWO6UDBVMGGBGQLVLN2VFANCNFSM5WMECLNQ. You are receiving this because you commented.