PowerShell module Posh-SSH - How to pass escape characters

78 views Asked by At

My first question here so sorry if I get the formatting wrong. I will try my best. I am using PowerShell and the Posh-SSH module.

I am trying to use PowerShell to SSH into a Citrix ADC (NetScaler). I am using the following code

$session = New-SSHSession -ComputerName nsr1.example.com

This works fine and I see the active connection.

I then use the follow command to send two commands, the first command goes into the FreeBSD shell of the ADC.

Shell

The second command is telnet IP Port

The whole command looks like

Invoke-SSHCommand -Command 'shell "telnet 192.168.57.14 8080"'

This then times out after a minute or less if i set the -Timeout option.

However here is my ask that I can't figure out.

If the connection is success I should get the following returned

telnet 1.2.3.4 8080
Trying 1.2.3.4...
Connected to FQDN.
Escape character is '^]'.

How do I pass the escape character.

(^]) using its ASCII code (0x1D), I tried passing it onto the end of command

Invoke-SSHCommand -Command 'shell "telnet 192.168.57.14 8080 [char]0x1D"'

I get presented with the Error being passed in the output

Invoke-SSHCommand -Command 'shell "telnet 1.2.3.4 8080 [char]0x1D"'
cmdlet Invoke-SSHCommand at command pipeline position 1
Supply values for the following parameters:
SessionId[0]: 6
SessionId[1]: 


Host       : nsr1.example.com
Output     : {Warning: One or more RPC nodes are configured with default passwords. For enhanced security, you must change the default RPC node password.,  Done, ERROR: }
ExitStatus : 1

So I am assuming the ERROR is the escape character not working as I had hoped. If someone has any pointers on what I am missing that would be great.

Update - I have been been doing further reading and learning and am still struggling to get the escape sequence of ^] to be passed. I have tried the following commands

    Invoke-SSHCommand -SessionId "0" -Command 'shell "telnet 1.2.3.4 8080; ^]; \r"'
    and
    # Establish the telnet connection
    Invoke-SSHCommand -SessionId "0" -Command 'shell "telnet 1.2.3.4 8080"' -TimeOut 60
    #Wait for a moment
Start-Sleep -Seconds 2
    #Send the escape character (^]) to interact with telnet session
Invoke-SSHCommand -SessionId "0" -Command 'shell "^]"'
    #Send the return/enter key to complete the interaction
Invoke-SSHCommand -SessionId "0" -Command 'shell "\r"'
0

There are 0 answers