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

 
Keymaster
1 month, 3 weeks ago.

  • Author
    Posts
  • #114129

    Participant
    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

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

    -SSHTRansport is only available on one parameter set:

    New-PSSession
    
    [-HostName] 
    
    [-Name ]
    
    [-Port ]
    
    [-UserName ]
    
    [-KeyFilePath 
    
    [-Subsystem ]
    
    [-SSHTransport]
    
    []

    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...?

You must be logged in to reply to this topic.