Unregister-PSSessionConfiguration
從電腦刪除已註冊的工作階段設定。
Syntax
Unregister-PSSessionConfiguration
[-Name] <String>
[-Force]
[-NoServiceRestart]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
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 (https://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 設定的會話。 這次,會話會失敗,因為 WinRM 服務重新啟動時已刪除 MaintenanceShell 設定。
參數
-Confirm
在執行 Cmdlet 前提示您確認。
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
指出 Cmdlet 不會提示您進行確認,並會在不提示的情況下重新啟動 WinRM 服務。 重新啟動服務可讓設定變更生效。
若要避免重新啟動並抑制重新啟動提示,請使用 NoServiceRestart 參數。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Name
指定要刪除的工作階段設定名稱。 輸入一個工作階段設定名稱或設定名稱模式。 允許使用萬用字元。 此為必要參數。
您也可以使用管線將會話組態傳送至 Unregister-PSSessionConfiguration
。
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | True |
-NoServiceRestart
指出此 Cmdlet 不會重新啟動 WinRM 服務,且會抑制重新啟動服務的提示。
根據預設,當您執行 Unregister-PSSessionConfiguration
命令時,系統會提示您重新啟動 WinRM 服務,讓變更生效。 在 WinRM 服務重新啟動之前,即使找不到,使用者仍然可以使用未註冊的會話設定 Get-PSSessionConfiguration
。
若要重新啟動 WinRM 服務而不提示,請指定 Force 參數。 若要手動重新啟動 WinRM 服務,請使用 Restart-Service
Cmdlet。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
顯示執行 Cmdlet 後會發生的情況。 Cmdlet 並不會執行。
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
輸入
Microsoft.PowerShell.Commands.PSSessionConfigurationCommands
您可以使用管線將會話組態物件從 Get-PSSessionConfiguration
傳送至此 Cmdlet。
輸出
None
此 Cmdlet 不會傳回任何物件。
備註
若要執行此 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