PS SSH Remoting: Non-interactive login with -HostName and -SSHTransport

Welcome Forums General PowerShell Q&A PS SSH Remoting: Non-interactive login with -HostName and -SSHTransport

This topic contains 1 reply, has 2 voices, and was last updated by

10 months, 1 week ago.

  • Author
  • #114129

    Topics: 2
    Replies: 0
    Points: 0
    Rank: Member

    For PS SSH Remoting, I can't seem to find a non-interactive way to to obtain a session using New-PSSession, which for my command must include -HostName and -SSHTransport:


    PS /home/gmonkey/scripts> $session = New-PSSession -HostName windns -Credential $cred -SSHTransport
    New-PSSession : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.
    At line:1 char:12
    + $session = New-PSSession -HostName windns -Credential $cred -SSHTrans ...
    +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-PSSession], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.NewPSSessionCommand

    Is there a way to achieve this ?

  • #114268

    Topics: 13
    Replies: 4872
    Points: 1,843
    Helping HandTeam Member
    Rank: Community Hero

    -SSHTRansport is only available on one parameter set:

    [-Name ]
    [-Port ]
    [-UserName ]
    [-Subsystem ]

    You can use -HostName, but not -Credential. The expectation is that you'd use -UserName, and the SSH transport is going to prompt you for your password. That's how SSH works. SSH isn't capable of accepting a PSCredential object, so there's no way to pass a full -Credential to it. That's more a limitation of how SSH is implemented than anything. I'd expect you to use a -KeyFilePath vs. a credential, given that it's SSH. See example 14 in the New-PSSession help...?

The topic ‘PS SSH Remoting: Non-interactive login with -HostName and -SSHTransport’ is closed to new replies.