PowerShell SSH remoting
PowerShell 7 can use SSH as a remoting transport instead of WinRM. That is what makes remoting work between Windows, Linux and macOS.
Documentation: Microsoft Learn
Overview
The parameters change rather than the cmdlets. Instead of -ComputerName you pass -HostName, and instead of Windows credentials you pass -UserName with key-based authentication. Invoke-Command -HostName host -UserName user -ScriptBlock { } is the shape.
Setup is on both ends. The client needs an SSH client. The target needs an SSH server with a PowerShell subsystem entry in sshd_config pointing at pwsh. Getting that subsystem line right is the step people miss, and the symptom is a connection that authenticates and then immediately closes.
The differences from WinRM are worth knowing before you choose. SSH remoting does not support the double-hop delegation options WinRM has, and it has no equivalent of JEA constrained endpoints. It authenticates with keys rather than Kerberos. For cross-platform work it is the only option; for a pure Windows domain, WinRM gives you more control.
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
$conn = [pscustomobject]@{
HostName = 'lin01.corp.local'
UserName = 'admin'
Method = 'SSH'
Command = 'Invoke-Command -HostName lin01.corp.local -UserName admin -ScriptBlock { $PSVersionTable.PSEdition }'
}
$conn | Format-List- Stage 1$conn
Positional values or no named parameters - Stage 2Format-List
Positional values or no named parameters
What happens
This prints the connection details as a list rather than opening a connection, since this console has no network. Format-List is used because five properties would be squeezed into an unreadable table. Note -HostName and -UserName in the Command value: those two parameters are how you tell PowerShell to use SSH instead of WinRM.
Worth remembering
- PowerShell 7 only. Use -HostName and -UserName, not -ComputerName.
- The target's sshd_config needs a PowerShell subsystem entry.
- Authentication is by SSH key, not Kerberos.
- No JEA and no delegation options, unlike WinRM.
Primary documentation
Try it
Illustrative output · values vary by environment
Example reader
Inspect this page's example
Run supported commands against the practice data, or inspect the example without executing it.
Ready to inspect.
Prints SSH remoting connection details as a list.
Show reference output
Illustrative output · values vary by environment
HostName : lin01.corp.local
UserName : admin
Method : SSH
Command : Invoke-Command -HostName lin01.corp.local -UserName admin -ScriptBlock { $PSVersionTable.PSEdition }