diff --git a/reference/6/Microsoft.PowerShell.Core/Enter-PSSession.md b/reference/6/Microsoft.PowerShell.Core/Enter-PSSession.md index 9140e98aeb32..3ce4802bba4f 100644 --- a/reference/6/Microsoft.PowerShell.Core/Enter-PSSession.md +++ b/reference/6/Microsoft.PowerShell.Core/Enter-PSSession.md @@ -154,14 +154,14 @@ You can also use the **Exit** keyword to end the interactive session. ### Example 6: Start an interactive session using SSH ``` -PS C:\> Enter-PSSession -HostName LinuxServer01 -UserName UserA +PS C:\> Enter-PSSession -HostName UserA@LinuxServer01 ``` This example shows how to start an interactive session using Secure Shell (SSH). If SSH is configured on the remote computer to prompt for passwords then you will get a password prompt. Otherwise you will have to use SSH key based user authentication. ### Example 7: Start an interactive session using SSH and specify the Port and user authentication key ``` -PS C:\> Enter-PSSession -HostName LinuxServer02 -UserName UserA -Port 22 -KeyFilePath c:\\userAKey_rsa +PS C:\> Enter-PSSession -HostName UserA@LinuxServer02:22 -KeyFilePath c:\\userAKey_rsa ``` This example shows how to start an interactive session using SSH. It uses the *Port* parameter to specify the port to use and the *KeyFilePath* parameter to specify an RSA key used to authenticate the user on the remote computer. @@ -419,6 +419,10 @@ Accept wildcard characters: False ### -HostName Specifies a computer name for a Secure Shell (SSH) based connection. This is similar to the *ComputerName* parameter except that the connection to the remote computer is made using SSH rather than Windows WinRM. +This parameter supports specifying the user name and/or port as part of the host name parameter value using +the form `user@hostname:port`. +The user name and/or port specified as part of the host name takes precedent over the `-UserName` and `-Port` parameters, if specified. +This allows passing multiple computer names to this parameter where some have specific user names and/or ports, while others use the user name and/or port from the `-UserName` and `-Port` parameters. This parameter was introduced in PowerShell 6.0. diff --git a/reference/6/Microsoft.PowerShell.Core/Invoke-Command.md b/reference/6/Microsoft.PowerShell.Core/Invoke-Command.md index e380b61572b1..d80f67c8632e 100644 --- a/reference/6/Microsoft.PowerShell.Core/Invoke-Command.md +++ b/reference/6/Microsoft.PowerShell.Core/Invoke-Command.md @@ -491,21 +491,21 @@ To get the results of commands and scripts that run in disconnected sessions, us ### Example 17: Run a command on a remote computer using SSH ``` -PS C:\> Invoke-Command -HostName LinuxServer01 -UserName UserA -ScriptBlock { Get-MailBox * } +PS C:\> Invoke-Command -HostName UserA@LinuxServer01 -ScriptBlock { Get-MailBox * } ``` This example shows how to run a command on a remote computer using Secure Shell (SSH). If SSH is configured on the remote computer to prompt for passwords then you will get a password prompt. Otherwise you will have to use SSH key based user authentication. ### Example 18: Run a command on a remote computer using SSH and specify a user authentication key ``` -PS C:\> Invoke-Command -HostName LinuxServer01 -UserName UserA -ScriptBlock { Get-MailBox * } -KeyFilePath c:\\userAKey_rsa +PS C:\> Invoke-Command -HostName UserA@LinuxServer01 -ScriptBlock { Get-MailBox * } -KeyFilePath c:\\userAKey_rsa ``` This example shows how to run a command on a remote computer using SSH and specifying a key file for user authentication. You will not get a password prompt unless the key authentication fails and the remote computer is configured to allow basic password authentication. ### Example 19: Run a script file on multiple remote computers using SSH as a job ``` -PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="LinuxServer5"; UserName="UserB"; KeyFilePath="c:\UserB\\id_rsa } +PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="UserB@LinuxServer5"; KeyFilePath="c:\UserB\\id_rsa } PS C:\> $results = Invoke-Command -FilePath c:\Scripts\CollectEvents.ps1 -SSHConnection $sshConnections ``` @@ -1168,6 +1168,10 @@ Accept wildcard characters: False ### -HostName Specifies an array of computer names for a Secure Shell (SSH) based connection. This is similar to the ComputerName parameter except that the connection to the remote computer is made using SSH rather than Windows WinRM. +This parameter supports specifying the user name and/or port as part of the host name parameter value using +the form `user@hostname:port`. +The user name and/or port specified as part of the host name takes precedent over the `-UserName` and `-Port` parameters, if specified. +This allows passing multiple computer names to this parameter where some have specific user names and/or ports, while others use the user name and/or port from the `-UserName` and `-Port` parameters. This parameter was introduced in PowerShell 6.0. @@ -1248,6 +1252,7 @@ Accept wildcard characters: False This parameter takes an array of hashtables where each hashtable contains one or more connection parameters needed to establish a Secure Shell (SSH) connection (HostName, Port, UserName, KeyFilePath). The hashtable connection parameters are the same as defined for the HostName parameter set. +Note that the order of the keys in the hashtable result in user name and port being used for the connection where the last one specified is used. For example, if you use `@{UserName="first";HostName="second@host"}`, then the user name `second` will be used. However, if you use `@{HostName="second@host:22";Port=23}`, then port 23 will be used. The SSHConnection parameter is useful for creating multiple sessions where each session requires different connection information. diff --git a/reference/6/Microsoft.PowerShell.Core/New-PSSession.md b/reference/6/Microsoft.PowerShell.Core/New-PSSession.md index 5da5b8e546e9..ed97c674600b 100644 --- a/reference/6/Microsoft.PowerShell.Core/New-PSSession.md +++ b/reference/6/Microsoft.PowerShell.Core/New-PSSession.md @@ -213,19 +213,19 @@ The value of the SessionOption parameter is the **SessionOption** object in the ### Example 12: Create a session using SSH ``` -PS C:\> New-PSSession -HostName LinuxServer01 -UserName UserA +PS C:\> New-PSSession -HostName UserA@LinuxServer01 ``` This example shows how to create a new **PSSession** using Secure Shell (SSH). If SSH is configured on the remote computer to prompt for passwords then you will get a password prompt. Otherwise you will have to use SSH key based user authentication. ### Example 13: Create a session using SSH and specify the port and user authentication key ``` -PS C:\> New-PSSession -HostName LinuxServer01 -UserName UserA -Port 22 -KeyFilePath c:\\userAKey_rsa +PS C:\> New-PSSession -HostName UserA@LinuxServer01:22 -KeyFilePath c:\\userAKey_rsa ``` This example shows how to create a **PSSession** using Secure Shell (SSH). It uses the *Port* parameter to specify the port to use and the *KeyFilePath* parameter to specify an RSA key used to identify and authenticate the user on the remote computer. ### Example 14: Create multiple sessions using SSH ``` -PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="LinuxServer5"; UserName="UserB"; KeyFilePath="c:\UserB\\id_rsa } +PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="UserB@LinuxServer5"; KeyFilePath="c:\UserB\\id_rsa } PS C:\> New-PSSession -SSHConnection $sshConnections ``` This example shows how to create multiple sessions using Secure Shell (SSH) and the **SSHConnection** parameter set. The *SSHConnection* parameter takes an array of hash tables that contain connection information for each session. Note that this example requires that the target remote computers have SSH configured to support key based user authentication. @@ -693,6 +693,10 @@ Accept wildcard characters: False ### -HostName Specifies an array of computer names for a Secure Shell (SSH) based connection. This is similar to the ComputerName parameter except that the connection to the remote computer is made using SSH rather than Windows WinRM. +This parameter supports specifying the user name and/or port as part of the host name parameter value using +the form `user@hostname:port`. +The user name and/or port specified as part of the host name takes precedent over the `-UserName` and `-Port` parameters, if specified. +This allows passing multiple computer names to this parameter where some have specific user names and/or ports, while others use the user name and/or port from the `-UserName` and `-Port` parameters. This parameter was introduced in PowerShell 6.0. @@ -773,10 +777,12 @@ Accept wildcard characters: False This parameter takes an array of hashtables where each hashtable contains one or more connection parameters needed to establish a Secure Shell (SSH) connection (HostName, Port, UserName, KeyFilePath). The hashtable connection parameters are the same as defined for the **HostName** parameter set. +Note that the order of the keys in the hashtable result in user name and port being used for the connection where the last one specified is used. For example, if you use `@{UserName="first";HostName="second@host"}`, then the user name `second` will be used. However, if you use `@{HostName="second@host:22";Port=23}`, then port 23 will be used. + +This parameter was introduced in PowerShell 6.0. The *SSHConnection* parameter is useful for creating multiple sessions where each session requires different connection information. -This parameter was introduced in PowerShell 6.0. ```yaml Type: hashtable