Connect-PSSession
重新连接到断开连接的会话。
语法
Name (默认值)
Connect-PSSession
-Name <String[]>
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Session
Connect-PSSession
[-Session] <PSSession[]>
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ComputerNameGuid
Connect-PSSession
-ComputerName <String[]>
-InstanceId <Guid[]>
[-ApplicationName <String>]
[-ConfigurationName <String>]
[-Credential <PSCredential>]
[-Authentication <AuthenticationMechanism>]
[-CertificateThumbprint <String>]
[-Port <Int32>]
[-UseSSL]
[-SessionOption <PSSessionOption>]
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ComputerName
Connect-PSSession
-ComputerName <String[]>
[-ApplicationName <String>]
[-ConfigurationName <String>]
[-Name <String[]>]
[-Credential <PSCredential>]
[-Authentication <AuthenticationMechanism>]
[-CertificateThumbprint <String>]
[-Port <Int32>]
[-UseSSL]
[-SessionOption <PSSessionOption>]
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ConnectionUriGuid
Connect-PSSession
[-ConnectionUri] <Uri[]>
-InstanceId <Guid[]>
[-ConfigurationName <String>]
[-AllowRedirection]
[-Credential <PSCredential>]
[-Authentication <AuthenticationMechanism>]
[-CertificateThumbprint <String>]
[-SessionOption <PSSessionOption>]
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ConnectionUri
Connect-PSSession
[-ConnectionUri] <Uri[]>
[-ConfigurationName <String>]
[-AllowRedirection]
[-Name <String[]>]
[-Credential <PSCredential>]
[-Authentication <AuthenticationMechanism>]
[-CertificateThumbprint <String>]
[-SessionOption <PSSessionOption>]
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
InstanceId
Connect-PSSession
-InstanceId <Guid[]>
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Id
Connect-PSSession
[-Id] <Int32[]>
[-ThrottleLimit <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Connect-PSSession cmdlet 重新连接到已断开连接的用户管理的 Windows PowerShell 会话(PSSessions)。
它适用于有意断开连接的会话,例如使用 Disconnect-PSSession cmdlet 或
Connect-PSSession 可以连接到同一用户启动的任何断开连接的会话。 其中包括从其他计算机上的其他会话启动或断开连接的会话。
但是,Connect-PSSession 无法连接到中断或关闭的会话,或者使用 Enter-PSSession cmdlet 启动的交互式会话。 此外,不能将会话连接到其他用户启动的会话,除非可以提供创建会话的用户的凭据。
有关断开连接会话功能的详细信息,请参阅about_Remote_Disconnected_Sessions。
此 cmdlet 已在 Windows PowerShell 3.0 中引入。
示例
示例 1:重新连接到会话
PS C:\> Connect-PSSession -ComputerName Server01 -Name ITTask
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
4 ITTask Server01 Opened ITTasks Available
此命令重新连接到 Server01 计算机上的 ITTask 会话。
输出显示命令成功。 会话的 状态 已打开,可用性 可用,指示可以在会话中运行命令。
示例 2:断开连接和重新连接的效果
PS C:\> Get-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Backups Localhost Opened Microsoft.PowerShell Available
PS C:\> Get-PSSession | Disconnect-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Backups Localhost Disconnected Microsoft.PowerShell None
PS C:\> Get-PSSession | Connect-PSSession
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Backups Localhost Opened Microsoft.PowerShell Available
此示例显示断开连接,然后重新连接到会话的效果。
第一个命令使用 Get-PSSession cmdlet。 如果没有 ComputerName 参数,该命令仅获取在当前会话中创建的会话。
输出显示命令获取本地计算机上的备份会话。 会话的 状态 已打开,可用性 可用。
第二个命令使用 Get-PSSession cmdlet 来获取在当前会话中创建的 PSSession 对象,以及 Disconnect-PSSession cmdlet 来断开会话的连接。 输出显示备份会话已断开连接。 会话的 状态 已断开连接,可用性 为 None。
第三个命令使用 Get-PSSession cmdlet 来获取在当前会话中创建的 PSSession 对象,以及 Connect-PSSession cmdlet 重新连接会话。 输出显示备份会话已重新连接。 会话的 状态 已打开,可用性 可用。
如果在未断开连接的会话上使用 Connect-PSSession cmdlet,该命令不会影响会话,并且不会生成任何错误。
示例 3:企业方案中的一系列命令
The administrator starts by creating a sessions on a remote computer and running a script in the session.The first command uses the **New-PSSession** cmdlet to create the ITTask session on the Server01 remote computer. The command uses the *ConfigurationName* parameter to specify the ITTasks session configuration. The command saves the sessions in the $s variable.
PS C:\> $s = New-PSSession -ComputerName Server01 -Name ITTask -ConfigurationName ITTasks
The second command **Invoke-Command** cmdlet to start a background job in the session in the $s variable. It uses the *FilePath* parameter to run the script in the background job.
PS C:\> Invoke-Command -Session $s {Start-Job -FilePath \\Server30\Scripts\Backup-SQLDatabase.ps1}
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
2 Job2 Running True Server01 \\Server30\Scripts\Backup...
The third command uses the Disconnect-PSSession cmdlet to disconnect from the session in the $s variable. The command uses the *OutputBufferingMode* parameter with a value of Drop to prevent the script from being blocked by having to deliver output to the session. It uses the *IdleTimeoutSec* parameter to extend the session time-out to 15 hours.When the command is completed, the administrator locks her computer and goes home for the evening.
PS C:\> Disconnect-PSSession -Session $s -OutputBufferingMode Drop -IdleTimeoutSec 60*60*15
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 ITTask Server01 Disconnected ITTasks None
Later that evening, the administrator starts her home computer, logs on to the corporate network, and starts Windows PowerShell. The fourth command uses the Get-PSSession cmdlet to get the sessions on the Server01 computer. The command finds the ITTask session.The fifth command uses the **Connect-PSSession** cmdlet to connect to the ITTask session. The command saves the session in the $s variable.
PS C:\> Get-PSSession -ComputerName Server01 -Name ITTask
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 ITTask Server01 Disconnected ITTasks None
PS C:\> $s = Connect-PSSession -ComputerName Server01 -Name ITTask
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 ITTask Server01 Opened ITTasks Available
The sixth command uses the **Invoke-Command** cmdlet to run a Get-Job command in the session in the $s variable. The output shows that the job finished successfully.The seventh command uses the **Invoke-Command** cmdlet to run a Receive-Job command in the session in the $s variable in the session. The command saves the results in the $BackupSpecs variable.The eighth command uses the **Invoke-Command** cmdlet to runs another script in the session. The command uses the value of the $BackupSpecs variable in the session as input to the script.
PS C:\> Invoke-Command -Session $s {Get-Job}
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
2 Job2 Completed True Server01 \\Server30\Scripts\Backup...
PS C:\> Invoke-Command -Session $s {$BackupSpecs = Receive-Job -JobName Job2}
PS C:\> Invoke-Command -Session $s {\\Server30\Scripts\New-SQLDatabase.ps1 -InitData $BackupSpecs.Initialization}
The ninth command disconnects from the session in the $s variable.The administrator closes Windows PowerShell and closes the computer. She can reconnect to the session on the next day and check the script status from her work computer.
PS C:\> Disconnect-PSSession -Session $s -OutputBufferingMode Drop -IdleTimeoutSec 60*60*15
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 ITTask Server01 Disconnected ITTasks None
此系列命令演示如何在企业方案中使用 Connect-PSSession cmdlet。 在这种情况下,系统管理员会在远程计算机上的会话中启动长时间运行的作业。 启动作业后,管理员会断开会话的连接,然后回家。 当晚晚些时候,管理员登录到她的主计算机,并验证作业是否运行,直到作业完成。
参数
-AllowRedirection
指示此 cmdlet 允许将此连接重定向到备用 URI。
使用 ConnectionURI 参数时,远程目标可以返回重定向到其他 URI 的指令。 默认情况下,Windows PowerShell 不会重定向连接,但你可以使用此参数来允许它重定向连接。
还可以通过更改 MaximumConnectionRedirectionCount 会话选项值来限制连接重定向的次数。 使用 New-PSSessionOption cmdlet 的 MaximumRedirection 参数,或设置 $PSSessionOption 首选项变量的 MaximumConnectionRedirectionCount 属性。 默认值为 5。
参数属性
| 类型: | SwitchParameter |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ConnectionUriGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-ApplicationName
指定应用程序的名称。 此 cmdlet 仅连接到使用指定应用程序的会话。
输入连接 URI 的应用程序名称段。
例如,在以下连接 URI 中,应用程序名称为 WSMan:https://localhost:5985/WSMAN。
会话的应用程序名称存储在会话的 Runspace.ConnectionInfo.AppName 属性中。
此参数的值用于选择和筛选会话。 它不会更改会话使用的应用程序。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-Authentication
指定用于对命令中的用户凭据进行身份验证的机制,以重新连接到断开连接的会话。 此参数的可接受值为:
- 违约
- 基本
- Credssp
- 摘要
- Kerberos
- 谈判
- NegotiateWithImplicitCredential
默认值为 Default。
有关此参数的值的详细信息,请参阅 MSDN 库中 AuthenticationMechanism 枚举。
警告:凭据安全支持提供程序(CredSSP)身份验证(其中用户凭据传递到要进行身份验证的远程计算机)旨在用于需要对多个资源进行身份验证的命令,例如访问远程网络共享。 此机制会增加远程操作的安全风险。 如果远程计算机遭到入侵,则传递给它的凭据可用于控制网络会话。
参数属性
| 类型: | AuthenticationMechanism |
| 默认值: | None |
| 接受的值: | Default, Basic, Negotiate, NegotiateWithImplicitCredential, Credssp, Digest, Kerberos |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUriGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-CertificateThumbprint
指定有权连接到断开连接的会话的用户帐户的数字公钥证书 (X509)。 输入证书的证书指纹。
证书用于基于客户端证书的身份验证。 它们只能映射到本地用户帐户。 它们不适用于域帐户。
若要获取证书指纹,请使用 Windows PowerShell 证书:驱动器中的 Get-Item 或 Get-ChildItem 命令。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUriGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-ComputerName
指定存储断开连接会话的计算机。 会话存储在位于服务器端或接收连接的计算机上。 默认值为本地计算机。
键入 NetBIOS 名称、IP 地址或一台计算机的完全限定域名。 不允许使用通配符。 若要指定本地计算机,请键入计算机名称、localhost 或点 (.)
参数属性
| 类型: | String[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | Cn |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-ConfigurationName
仅连接到使用指定会话配置的会话。
输入会话配置的配置名称或完全限定的资源 URI。
如果仅指定配置名称,则前面有以下架构 URI:https://schemas.microsoft.com/powershell。
会话的配置名称存储在会话的 ConfigurationName 属性中。
此参数的值用于选择和筛选会话。 它不会更改会话使用的会话配置。
有关会话配置的详细信息,请参阅 about_Session_Configurations。
参数属性
| 类型: | String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
ConnectionUriGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | cf |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-ConnectionUri
指定断开连接会话的连接终结点的 URI。
URI 必须完全限定。 此字符串的格式如下所示:
\<Transport\>://\<ComputerName\>:\<Port\>/\<ApplicationName\>
默认值如下所示:
https://localhost:5985/WSMAN
如果未指定连接 URI,可以使用 UseSSL 和 端口 参数来指定连接 URI 值。
URI 传输 段的有效值为 HTTP 和 HTTPS。 如果使用传输段指定连接 URI,但不指定端口,则会使用标准端口创建会话:80 用于 HTTP,对于 HTTPS 为 443。 若要使用 Windows PowerShell 远程处理的默认端口,请为 HTTP 指定端口 5985,或为 HTTPS 指定端口 5986。
如果目标计算机将连接重定向到其他 URI,则除非在命令中使用 AllowRedirection 参数,否则 Windows PowerShell 将阻止重定向。
参数属性
| 类型: | Uri[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | URI, CU |
参数集
ConnectionUriGuid
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-Credential
指定有权连接到断开连接的会话的用户帐户。 默认值为当前用户。
键入用户名,例如 User01 或 Domain01\User01。 或者,输入 PSCredential 对象,例如由 Get-Credential cmdlet 生成的对象。 如果键入用户名,此 cmdlet 会提示输入密码。
参数属性
| 类型: | PSCredential |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUriGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Id
指定断开连接会话的 ID。 ID 参数只有在断开的会话之前连接到当前会话时才起作用。
当会话存储在本地计算机上但未连接到当前会话时,此参数有效,但无效。
参数属性
| 类型: | Int32[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
Id
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-InstanceId
指定断开连接会话的实例 ID。
实例 ID 是一个 GUID,用于唯一标识本地或远程计算机上的 PSSession。
实例 ID 存储在 PSSession的 InstanceID 属性中。
参数属性
| 类型: | Guid[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUriGuid
| Position: | Named |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
InstanceId
| Position: | Named |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Name
指定断开连接的会话的友好名称。
参数属性
| 类型: | String[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
Name
| Position: | Named |
| 必需: | True |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Port
指定远程计算机上的网络端口,用于重新连接到会话。 若要连接到远程计算机,远程计算机必须侦听连接使用的端口。 默认端口为 5985,即 HTTP 的 WinRM 端口,5986 是 HTTPS 的 WinRM 端口。
在使用备用端口之前,必须在远程计算机上配置 WinRM 侦听器以侦听该端口。 若要配置侦听器,请在 Windows PowerShell 提示符处键入以下两个命令:
Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse
New-Item -Path WSMan:\Localhost\listener -Transport http -Address * -Port \<port-number\>
除非必须,否则不要使用 Port 参数。 命令中设置的端口适用于运行命令的所有计算机或会话。 备用端口设置可能会阻止命令在所有计算机上运行。
参数属性
| 类型: | Int32 |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-Session
指定断开连接的会话。 输入一个变量,其中包含 PSSession 对象或创建或获取 PSSession 对象的命令,例如 Get-PSSession 命令。
参数属性
| 类型: | PSSession[] |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
Session
| Position: | 0 |
| 必需: | True |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-SessionOption
指定会话的高级选项。 输入 SessionOption 对象,例如使用 New-PSSessionOption cmdlet 创建的会话选项,或键是会话选项名称的哈希表,值是会话选项值。
选项的默认值由$PSSessionOption首选项变量的值(如果已设置)确定。 否则,默认值由会话配置中设置的选项建立。
会话选项值优先于在$PSSessionOption首选项变量和会话配置中设置的会话的默认值。 但是,它们不优先于会话配置中设置的最大值、配额或限制。
有关包含默认值的会话选项的说明,请参阅 New-PSSessionOption。 有关 $PSSessionOption 首选项变量的信息,请参阅 about_Preference_Variables。 有关会话配置的详细信息,请参阅 about_Session_Configurations。
参数属性
| 类型: | PSSessionOption |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUriGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ConnectionUri
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-ThrottleLimit
指定可建立以运行此命令的最大并发连接数。 如果省略此参数或输入值 0,则使用默认值 32。
限制限制仅适用于当前命令,不适用于会话或计算机。
参数属性
| 类型: | Int32 |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-UseSSL
指示此 cmdlet 使用安全套接字层 (SSL) 协议连接到断开连接的会话。 默认情况下,不使用 SSL。
WS-Management 加密通过网络传输的所有 Windows PowerShell 内容。 UseSSL 参数是一种额外的保护,用于跨 HTTPS 连接而不是 HTTP 连接发送数据。
如果使用此参数,但 SSL 在用于命令的端口上不可用,命令将失败。
参数属性
| 类型: | SwitchParameter |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
ComputerNameGuid
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
ComputerName
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。
参数属性
| 类型: | SwitchParameter |
| 默认值: | False |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | 无线 |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | False |
| 来自管道的值(按属性名称): | False |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
PSSession
可以通过管道将会话(PSSession)传递给此 cmdlet。
输出
PSSession
此 cmdlet 返回一个对象,该对象表示其重新连接到的会话。
备注
Connect-PSSession 仅重新连接到已断开连接的会话,即具有 状态 属性的已断开连接值的会话。 只有连接到或结束于运行 Windows PowerShell 3.0 或更高版本的计算机的会话才能断开连接并重新连接。
如果在未断开连接的会话上使用 Connect-PSSession,该命令不会影响会话,也不会生成错误。
使用使用 EnableNetworkAccess 参数创建的交互式令牌的断开连接环回会话只能从创建会话的计算机重新连接。 此限制可保护计算机免受恶意访问。
PSSession 的 State 属性的值相对于当前会话。 因此,断开连接 值表示 PSSession 未连接到当前会话。 但是,这并不意味着 PSSession 已与所有会话断开连接。 它可能连接到另一个会话。 若要确定是否可以连接或重新连接到会话,请使用 Availability 属性。
当可用性 的值为“无”时,表示可以连接到会话。 “忙碌”值表示无法连接到 PSSession,因为它已连接到另一个会话。
有关会话 State 属性的值的详细信息,请参阅 MSDN 库中 RunspaceState 枚举。
有关会话 可用性 属性的值的详细信息,请参阅 MSDN 库中 RunspaceAvailability 枚举。
连接到 PSSession时,无法更改 PSSession 的空闲超时值。 Connect-PSSession
SessionOption 参数采用具有IdleTimeout 值的SessionOption 对象。 但是,连接到 PSSession时,将忽略 SessionOption 对象的 IdleTimeout 值,$PSSessionOption变量的 IdleTimeout 值。通过使用
New-PSSession 或Invoke-Command cmdlet,创建PSSession 时,可以设置和更改 PSSession 的空闲超时。PSSession 的 IdleTimeout 属性对于断开连接的会话至关重要,因为它确定在远程计算机上维护断开连接的会话的时间。 断开连接的会话从其断开连接的时刻起就被视为空闲,即使命令正在断开连接的会话中运行也是如此。
相关链接
- Disconnect-PSSession
- Enter-PSSession
- Exit-PSSession
- Get-PSSession
- Get-PSSessionConfiguration
- New-PSSession
- New-PSSessionOption
- New-PSTransportOption
- Receive-PSSession
- Register-PSSessionConfiguration
- Remove-PSSession
- about_PSSessions
- about_Remote
- about_Remote_Disconnected_Sessions
- about_Session_Configurations