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>]
Description
Connect-PSSession Cmdlet 會重新連線到已中斷連線的使用者管理 Windows PowerShell 會話(PSSessions)。 它適用於刻意中斷連線的會話,例如使用 Disconnect-PSSession Cmdlet 或 InDisconnectedSession 參數 Invoke-Command 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
- 談判
- 使用隱式憑證進行協商
預設值為 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 和 Port 參數來指定連線 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 參數僅在已中斷的會話先前連接到目前的會話時生效。
當會話儲存在本機計算機上,但未連線到目前的會話時,這個參數有效但無效。
參數屬性
| 類型: | Int32[] |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
Id
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-InstanceId
指定已中斷連線之會話的實例標識碼。
實例標識碼是 GUID,可唯一識別本機或遠端電腦上的 PSSession。
實例標識符會儲存在 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 只會重新連線到已中斷連線的會話,也就是說,State 屬性的值已中斷連線的會話。 只有連線到或結束於執行 Windows PowerShell 3.0 或更新版本的電腦的會話,才能中斷連線並重新連線。
如果您在未中斷連線的會話上使用 Connect-PSSession,則命令不會影響會話,而且不會產生錯誤。
使用 EnableNetworkAccess 參數所建立的互動式令牌已中斷連線的回送會話,只能從建立會話的計算機重新連線。 這項限制可保護計算機免於惡意存取。
PSSessionState 屬性的值相對於目前會話。 因此,Disconnected 的值表示 PSSession 未連線到目前的會話。 不過,這並不表示 PSSession 與所有會話中斷連線。 它可能會連線到不同的工作階段。 若要判斷您是否可以連線或重新連線到會話,請使用 Availability 屬性。
Availability 的值為 None 表示您可以連線到會話。 [忙碌] 的值表示您無法連線到 PSSession,因為它已連線到另一個會話。
如需會話
State 屬性值的詳細資訊,請參閱 MSDN 連結庫中的 runspaceState 列舉。 如需會話
可用性 屬性值的詳細資訊,請參閱 MSDN 連結庫中的 runspaceAvailability 列舉。 當您連線到 PSSession時,您無法變更 PSSession 的閑置逾時值。 Connect-PSSessionSessionOption 參數會採用具有 IdleTimeout 值的 SessionOption 物件。 不過,連接到 PSSession時,會忽略 IdleTimeout 值 SessionOption 物件和 $PSSessionOption 變數的 IdleTimeout 值。
當您建立 PSSession時,可以使用 New-PSSession 或 Invoke-Command Cmdlet,以及當您與 PSSession中斷連線時,您可以設定和變更 PSSession 的閑置逾時。
PSSession 的 IdleTimeout 屬性對於中斷連線的會話至關重要,因為它會決定遠端電腦上維護中斷聯機會話的時間長度。 即使在中斷連線的會話中命令仍在執行,從會話中斷連線的那一刻起,該會話仍會被視為閑置。