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

New-SSHRemotePortForward not portforwarding

Open dav101 opened this issue 5 years ago • 3 comments

I saw a old issue which has not been responded to so have created a new one, when calling New-SSHRemotePortForward it throws a error

New-SSHRemotePortForward -LocalAdress 192.168.4.8 -LocalPort 1337 -RemoteAddress 192.168.5.6 -RemotePort 3389 -Index 0

Throws error

Write-Verbose : Cannot bind argument to parameter 'Message' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.2\Posh-SSH.psm1:2704 char:31
+                 Write-Verbose $session.index
+                               ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Write-Verbose], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteVerboseCommand
`New-SSHRemotePortForward -LocalAdress 192.168.4.8 -LocalPort 1337 -RemoteAddress 192.168.5.6 -RemotePort 3389 -sshSession $CurrentSession

Throws error

Exception calling "Start" with "0" argument(s): "Port forwarding for '192.168.5.6' port '3389' failed to start."
At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.2\Posh-SSH.psm1:2724 char:17
+                 $SSHFWP.start()
+                 ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SshException

Note: I can portforward in a batch script and in git bash, issue is just when using this

Powershell version: 5.1.18362.752 Posh-ssh version: 2.2 from PSGallery OS: Windows 10

dav101 avatar Oct 01 '20 16:10 dav101

No problem, seems there is an issue with the underlying library. I may remove this cmdlet since dev on the library is so low which has impacted module releases as a consequence.

On Oct 1, 2020, at 12:47 PM, dav101 [email protected] wrote:

I saw a old issue https://github.com/darkoperator/Posh-SSH/issues/192 which has not been responded to so have created a new one, when calling New-SSHRemotePortForward it throws a error

New-SSHRemotePortForward -LocalAdress 192.168.4.8 -LocalPort 1337 -RemoteAddress 192.168.5.6 -RemotePort 3389 -Index 0

Throws error

Write-Verbose : Cannot bind argument to parameter 'Message' because it is null. At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.2\Posh-SSH.psm1:2704 char:31

  •             Write-Verbose $session.index
    
  •                           ~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Write-Verbose], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WriteVerboseCommand `New-SSHRemotePortForward -LocalAdress 192.168.4.8 -LocalPort 1337 -RemoteAddress 192.168.5.6 -RemotePort 3389 -sshSession $CurrentSession Throws error

Exception calling "Start" with "0" argument(s): "Port forwarding for '192.168.5.6' port '3389' failed to start." At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.2\Posh-SSH.psm1:2724 char:17

  •             $SSHFWP.start()
    
  •             ~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : SshException Note: I can portforward in a batch script and in git bash, issue is just when using this

Powershell version: 5.1.18362.752 Posh-ssh version: 2.2 from PSGallery OS: Windows 10

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/348, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7IHX7Z7AER3QCGHIY2ZTSISXDLANCNFSM4SAVPT5Q.

darkoperator avatar Oct 01 '20 16:10 darkoperator

I was just playing with this cmdlet and came across this error as well. Also the typo in the -LocalAddress option only having one "d" (-LocalAdress).

Write-Verbose: C:\Users\MMINOR\Documents\PowerShell\Modules\posh-ssh\3.0.0\Posh-SSH.psm1:2710

Anyway, I can see this is low-priority, but I feel better adding my 2 cents.

MikeMM70 avatar Apr 08 '21 21:04 MikeMM70

Hi, you can easily fix it by changing the index to SessionId:

        foreach($session in $Global:SshSessions)
        {
            Write-Verbose $session.SessionId
            if ($session.SessionId -eq $Index)
            {
                # Add the forward port object to the session
                Write-Verbose "Adding Forward Port Configuration to session $Index"
                $session.session.AddForwardedPort($SSHFWP)
                Write-Verbose "Starting the Port Forward."
                $SSHFWP.start()
                Write-Verbose "Forwarding has been started."
            }
        }

stephannn avatar Jul 27 '22 08:07 stephannn