Unregister-PSSessionConfiguration
從計算機刪除已註冊的工作階段組態。
語法
Unregister-PSSessionConfiguration
[-Name] <String>
[-Force]
[-NoServiceRestart]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
此 Cmdlet 僅適用於 Windows 平臺。
Cmdlet 會 Unregister-PSSessionConfiguration
從計算機刪除已註冊的工作階段組態。 此 Cmdlet 是針對系統管理員所設計,可管理使用者的自定義會話設定。
若要讓變更生效, Unregister-PSSessionConfiguration
請重新啟動 WinRM 服務。 若要防止重新啟動,請指定 NoServiceRestart 參數。
如果您不小心刪除預設 Microsoft.PowerShell
或 Microsoft.PowerShell32
會話組態,請使用 Enable-PSRemoting
Cmdlet 來還原它們。 如需詳細資訊,請參閱 about_Session_Configurations。
範例
範例 1:刪除工作階段設定
此範例會 MaintenanceShell
從計算機刪除會話組態。
Unregister-PSSessionConfiguration -Name "MaintenanceShell"
範例 2:刪除工作階段設定並重新啟動 WinRM 服務
在此範例中,我們會刪除設定 MaintenanceShell
,然後重新啟動 WinRM 服務。 Force 參數會隱藏所有使用者訊息,以重新啟動 WinRM 服務,而不提示。
Unregister-PSSessionConfiguration -Name MaintenanceShell -Force
範例 3:刪除所有工作階段設定
此範例示範兩種方式可刪除計算機上的所有會話設定。 這兩個命令的效果相同,而且可以交替使用。
Unregister-PSSessionConfiguration -Name *
Get-PSSessionConfiguration -Name * | Unregister-PSSessionConfiguration
範例 4:在不重新啟動的情況下取消註冊
此範例顯示使用 NoServiceRestart 參數來防止服務重新啟動而中斷電腦上任何會話的效果。
PS> Unregister-PSSessionConfiguration -Name "MaintenanceShell" -NoServiceRestart
PS> Get-PSSessionConfiguration -Name "MaintenanceShell"
Get-PSSessionConfiguration -Name MaintenanceShell : No Session Configuration matches criteria "MaintenanceShell".
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
PS> New-PSSession -ConfigurationName "MaintenanceShell"
Id Name ComputerName State Configuration Availability
-- ---- ------------ ----- ------------- ------------
1 Session1 localhost Opened MaintenanceShell Available
PS> Restart-Service winrm
PS> New-PSSession -ConfigurationName MaintenanceShell
[localhost] Connecting to remote server failed with the following error message :
The WS-Management service cannot process the request.
The resource URI (http://schemas.microsoft.com/powershell/MaintenanceShell) was not found in the WS-Management catalog.
The catalog contains the metadata that describes resources, or logical endpoints.
For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed
會 Unregister-PSSessionConfiguration
刪除 MaintenanceShell
會話組態。
不過,因為命令使用 NoServiceRestart 參數,因此 WinRM 服務不會重新啟動,而且變更尚未完全有效。
接下來,會 Get-PSSessionConfiguration
嘗試取得 MaintenanceShell
會話。 因為會話已從 WS-Management 資源數據表中移除,所以 Get-PSSessionConfiguration
無法傳回它。
Cmdlet New-PSSession
會使用 MaintenanceShell
組態建立會話。 命令成功。 接下來,我們會重新啟動 WinRM 服務。
最後, New-PSSession
Cmdlet 會嘗試建立使用組態的 MaintenanceShell
會話。 這次,工作階段會失敗,因為 MaintenanceShell
WinRM 服務重新啟動時已刪除設定。
參數
-Confirm
執行 Cmdlet 之前先提示您確認。
類型: | SwitchParameter |
別名: | cf |
Position: | Named |
預設值: | False |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Force
指出 Cmdlet 不會提示您進行確認,而且不會提示重新啟動 WinRM 服務。 重新啟動服務會讓設定變更生效。
若要防止重新啟動並隱藏重新啟動提示,請使用 NoServiceRestart 參數。
類型: | SwitchParameter |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-Name
指定要刪除的工作階段組態名稱。 輸入一個工作階段組態名稱或組態名稱模式。 允許通配符。 此為必要參數。
您也可以使用管線將會話組態傳送至 Unregister-PSSessionConfiguration
。
類型: | String |
Position: | 0 |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | True |
-NoServiceRestart
表示此 Cmdlet 不會重新啟動 WinRM 服務,並隱藏重新啟動服務的提示。
根據預設,當您執行 Unregister-PSSessionConfiguration
命令時,系統會提示您重新啟動 WinRM 服務,讓變更生效。 在 WinRM 服務重新啟動之前,使用者仍然可以使用未註冊的會話設定,即使 Get-PSSessionConfiguration
找不到。
若要重新啟動 WinRM 服務而不提示,請指定 Force 參數。 若要手動重新啟動 WinRM 服務,請使用 Restart-Service
Cmdlet。
類型: | SwitchParameter |
Position: | Named |
預設值: | None |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-WhatIf
顯示執行 Cmdlet 後會發生的情況。 未執行 Cmdlet。
類型: | SwitchParameter |
別名: | wi |
Position: | Named |
預設值: | False |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
輸入
Microsoft.PowerShell.Commands.PSSessionConfigurationCommands
您可以使用管線將會話組態物件傳送至此 Cmdlet。
輸出
None
此 Cmdlet 不會傳回任何輸出。
備註
此 Cmdlet 僅適用於 Windows 平臺。
若要執行此 Cmdlet,您必須使用 [ 以系統管理員 身分執行] 選項啟動 PowerShell。
相關連結
- Disable-PSSessionConfiguration
- Enable-PSSessionConfiguration
- Get-PSSessionConfiguration
- New-PSSessionConfigurationFile
- New-PSSessionOption
- Register-PSSessionConfiguration
- Set-PSSessionConfiguration
- Test-PSSessionConfigurationFile
- Unregister-PSSessionConfiguration
- WSMan 提供者
- about_Session_Configurations
- about_Session_Configuration_Files