Powershell 7 SSH Remoting

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
bill-douse
Posts: 17
Last visit: Mon Sep 25, 2023 3:12 pm

Powershell 7 SSH Remoting

Post by bill-douse »

Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.200
OS: Windows 10 Pro for Workstations (64 Bit)
Build: v10.0.19044.0
PSVersion: 7.2.1 & 7.3 Preview
PSEdition Core
----------------------------------------------------

Just a quick reach out to the PSS Community to see if anyone has a good answer for why Powershell 7.2/3 (aka., PWSH) SSH Remoting does not appear to support non-interactive SSH Remoting sessions in Cmdlets like Invoke-Command, Enter-PSSession, New-PSSession, etc.)? Basically, you can only pass half the user credentials (username only) in the Cmdlet and no support for passing the corresponding user password as a secure string. Maybe I am missing something here but, is there a good reason for not mirroring how PWSH's WinRM sessions are handled, in terms of available parameters? Not an expert by any stretch but, I would think that this would be a good feature, if not a necessity, to keep around in a cross-platform environment. No?

Appreciate any feedback, and especially appreciate any alternative approaches that make use of PWSH's SSH Remoting capabilities without having to fetch a password from the user before using an Invoke-Command to execute commands on a remote computer. Automation is only good when you keep the humans out of the loop. ;)

Thanks-a-million,
Bill D.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell 7 SSH Remoting

Post by jvierra »

If you search you will find many blogs that will explain how to set up PowerShell SSH remoting. There are also modules that will simplify SSH remoting. The remote system has to have this capability configured in advance.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell 7 SSH Remoting

Post by jvierra »

bill-douse
Posts: 17
Last visit: Mon Sep 25, 2023 3:12 pm

Re: Powershell 7 SSH Remoting

Post by bill-douse »

I had no problem configuring SSH Remoting. That's not the issue. My message was in regards to being able to pass a secure string password, along with the Username parameter, in a script using an Invoke-Command or New-PSSession cmdlet. For example, let's say I would like to perform a Start-Service cmdlet on a remote computer. Using a WinRM PS Remote session, I would use the following:

$creds = Get-Credential
$session = New-PSSession -ComputerName 'TestServer' -Credential $creds
Invoke-Command -$session -ScriptBlock {Start-Service CertSvc}

Now if I want to do the same using SSH transport, the code snippet "should" look like the following:

$creds = Get-Credential
$session = New-PSSession -Hostname 'TestServer' -Credential $creds <=[This is not supported with SSH]
Invoke-Command -$session -ScriptBlock {Start-Service CertSvc}

The only difference (IMHO) should be using the -Hostname instead of -ComputerName parameter to trigger SSH instead of WinRM. But, that's not the case. There is no '-Credential' parameter available when using SSH as the transport, which means that you can only provide a Username with the New-PSSession cmdlet and get prompted interactively on the console for a password. That does NOT work well in automation scripts.

Now, if I am missing something here please share. If you know of a way to get the same results in PS 7 SSHRemoting, I would be very appreciative.

-Bill D.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell 7 SSH Remoting

Post by jvierra »

Read the following carefully. It tells you how to pass credentials.

https://docs.microsoft.com/en-us/powers ... rshell-7.2
This topic is 2 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked