共用方式為


Unregister-PSSessionConfiguration

從計算機刪除已註冊的工作階段組態。

語法

Default (預設值)

Unregister-PSSessionConfiguration
    [-Name] <String>
    [-Force]
    [-NoServiceRestart]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

此 Cmdlet 只能在 Windows 平臺上使用。

Unregister-PSSessionConfiguration Cmdlet 會從計算機刪除已註冊的會話組態。 此 Cmdlet 是針對系統管理員所設計,可管理使用者的自定義會話設定。

若要讓變更生效,Unregister-PSSessionConfiguration 重新啟動 WinRM 服務。 若要防止重新啟動,請指定 NoServiceRestart 參數。

如果您不小心刪除預設 Microsoft.PowerShellMicrosoft.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 無法傳回它。

New-PSSession Cmdlet 會使用 MaintenanceShell 組態建立會話。 命令成功。 接下來,我們會重新啟動 WinRM 服務。

最後,New-PSSession Cmdlet 會嘗試建立使用 MaintenanceShell 組態的會話。 這次,工作階段會失敗,因為 WinRM 服務重新啟動時已刪除 MaintenanceShell 組態。

參數

-Confirm

在執行 Cmdlet 之前,提示您進行確認。

參數屬性

類型:SwitchParameter
預設值:False
支援萬用字元:False
不要顯示:False
別名:cf

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Force

指出 Cmdlet 不會提示您進行確認,而且不會提示重新啟動 WinRM 服務。 重新啟動服務會讓設定變更生效。

若要防止重新啟動並隱藏重新啟動提示,請使用 NoServiceRestart 參數。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Name

指定要刪除的工作階段組態名稱。 輸入一個工作階段組態名稱或組態名稱模式。 允許使用通配符字元。 這是必要參數。

您也可以使用管線將會話組態傳送至 Unregister-PSSessionConfiguration

參數屬性

類型:String
預設值:None
支援萬用字元:True
不要顯示:False

參數集

(All)
Position:0
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-NoServiceRestart

表示此 Cmdlet 不會重新啟動 WinRM 服務,並隱藏重新啟動服務的提示。

根據預設,當您執行 Unregister-PSSessionConfiguration 命令時,系統會提示您重新啟動WinRM服務,讓變更生效。 在 WinRM 服務重新啟動之前,使用者仍然可以使用未註冊的會話設定,即使 Get-PSSessionConfiguration 找不到它。

若要重新啟動 WinRM 服務而不提示,請指定 Force 參數。 若要手動重新啟動 WinRM 服務,請使用 Restart-Service Cmdlet。

參數屬性

類型:SwitchParameter
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
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

輸入

Microsoft.PowerShell.Commands.PSSessionConfigurationCommands

您可以使用管線將會話組態物件傳送至此 Cmdlet。

輸出

None

此 Cmdlet 不會傳回任何輸出。

備註

此 Cmdlet 僅適用於 Windows 平臺。

若要執行此 Cmdlet,您必須使用 [以 系統管理員身分執行] 選項 啟動 PowerShell。