Skip to content

Commit fb78f5d

Browse files
SteveL-MSFTSean Wheeler
authored andcommitted
Update docs for support of new hostname format (#2321)
* update remote cmdlets for new hostname syntax * update Enter-PSSession as well
1 parent ac405fb commit fb78f5d

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

reference/6/Microsoft.PowerShell.Core/Enter-PSSession.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ You can also use the **Exit** keyword to end the interactive session.
155155

156156
### Example 6: Start an interactive session using SSH
157157
```
158-
PS C:\> Enter-PSSession -HostName LinuxServer01 -UserName UserA
158+
PS C:\> Enter-PSSession -HostName UserA@LinuxServer01
159159
```
160160

161161
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.
162162

163163
### Example 7: Start an interactive session using SSH and specify the Port and user authentication key
164164
```
165-
PS C:\> Enter-PSSession -HostName LinuxServer02 -UserName UserA -Port 22 -KeyFilePath c:\<path>\userAKey_rsa
165+
PS C:\> Enter-PSSession -HostName UserA@LinuxServer02:22 -KeyFilePath c:\<path>\userAKey_rsa
166166
```
167167

168168
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.
@@ -423,6 +423,10 @@ Accept wildcard characters: False
423423
### -HostName
424424
Specifies a computer name for a Secure Shell (SSH) based connection.
425425
This is similar to the *ComputerName* parameter except that the connection to the remote computer is made using SSH rather than Windows WinRM.
426+
This parameter supports specifying the user name and/or port as part of the host name parameter value using
427+
the form `user@hostname:port`.
428+
The user name and/or port specified as part of the host name takes precedent over the `-UserName` and `-Port` parameters, if specified.
429+
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.
426430

427431
This parameter was introduced in PowerShell 6.0.
428432

reference/6/Microsoft.PowerShell.Core/Invoke-Command.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,21 +491,21 @@ To get the results of commands and scripts that run in disconnected sessions, us
491491

492492
### Example 17: Run a command on a remote computer using SSH
493493
```
494-
PS C:\> Invoke-Command -HostName LinuxServer01 -UserName UserA -ScriptBlock { Get-MailBox * }
494+
PS C:\> Invoke-Command -HostName UserA@LinuxServer01 -ScriptBlock { Get-MailBox * }
495495
```
496496

497497
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.
498498

499499
### Example 18: Run a command on a remote computer using SSH and specify a user authentication key
500500
```
501-
PS C:\> Invoke-Command -HostName LinuxServer01 -UserName UserA -ScriptBlock { Get-MailBox * } -KeyFilePath c:\<path>\userAKey_rsa
501+
PS C:\> Invoke-Command -HostName UserA@LinuxServer01 -ScriptBlock { Get-MailBox * } -KeyFilePath c:\<path>\userAKey_rsa
502502
```
503503

504504
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.
505505

506506
### Example 19: Run a script file on multiple remote computers using SSH as a job
507507
```
508-
PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="LinuxServer5"; UserName="UserB"; KeyFilePath="c:\UserB\<path>\id_rsa }
508+
PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="UserB@LinuxServer5"; KeyFilePath="c:\UserB\<path>\id_rsa }
509509
PS C:\> $results = Invoke-Command -FilePath c:\Scripts\CollectEvents.ps1 -SSHConnection $sshConnections
510510
```
511511

@@ -1171,6 +1171,10 @@ Accept wildcard characters: False
11711171

11721172
### -HostName
11731173
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.
1174+
This parameter supports specifying the user name and/or port as part of the host name parameter value using
1175+
the form `user@hostname:port`.
1176+
The user name and/or port specified as part of the host name takes precedent over the `-UserName` and `-Port` parameters, if specified.
1177+
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.
11741178

11751179
This parameter was introduced in PowerShell 6.0.
11761180

@@ -1251,6 +1255,7 @@ Accept wildcard characters: False
12511255
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, Subsystem).
12521256

12531257
The hashtable connection parameters are the same as defined for the HostName parameter set.
1258+
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.
12541259

12551260
The SSHConnection parameter is useful for creating multiple sessions where each session requires different connection information.
12561261

reference/6/Microsoft.PowerShell.Core/New-PSSession.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,19 @@ The value of the SessionOption parameter is the **SessionOption** object in the
214214

215215
### Example 12: Create a session using SSH
216216
```
217-
PS C:\> New-PSSession -HostName LinuxServer01 -UserName UserA
217+
PS C:\> New-PSSession -HostName UserA@LinuxServer01
218218
```
219219
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.
220220

221221
### Example 13: Create a session using SSH and specify the port and user authentication key
222222
```
223-
PS C:\> New-PSSession -HostName LinuxServer01 -UserName UserA -Port 22 -KeyFilePath c:\<path>\userAKey_rsa
223+
PS C:\> New-PSSession -HostName UserA@LinuxServer01:22 -KeyFilePath c:\<path>\userAKey_rsa
224224
```
225225
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.
226226

227227
### Example 14: Create multiple sessions using SSH
228228
```
229-
PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="LinuxServer5"; UserName="UserB"; KeyFilePath="c:\UserB\<path>\id_rsa }
229+
PS C:\> $sshConnections = @{ HostName="WinServer1"; UserName="domain\userA"; KeyFilePath="c:\users\UserA\id_rsa" }, @{ HostName="UserB@LinuxServer5"; KeyFilePath="c:\UserB\<path>\id_rsa }
230230
PS C:\> New-PSSession -SSHConnection $sshConnections
231231
```
232232
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.
@@ -697,6 +697,10 @@ Accept wildcard characters: False
697697

698698
### -HostName
699699
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.
700+
This parameter supports specifying the user name and/or port as part of the host name parameter value using
701+
the form `user@hostname:port`.
702+
The user name and/or port specified as part of the host name takes precedent over the `-UserName` and `-Port` parameters, if specified.
703+
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.
700704

701705
This parameter was introduced in PowerShell 6.0.
702706

@@ -777,10 +781,12 @@ Accept wildcard characters: False
777781
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, Subsystem).
778782

779783
The hashtable connection parameters are the same as defined for the **HostName** parameter set.
784+
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.
785+
786+
This parameter was introduced in PowerShell 6.0.
780787

781788
The *SSHConnection* parameter is useful for creating multiple sessions where each session requires different connection information.
782789

783-
This parameter was introduced in PowerShell 6.0.
784790

785791
```yaml
786792
Type: hashtable

0 commit comments

Comments
 (0)