Disable-PSSessionConfiguration
停用本機電腦上的會話設定。
語法
Default (預設值)
Disable-PSSessionConfiguration
[[-Name] <String[]>]
[-Force]
[-NoServiceRestart]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Disable-PSSessionConfiguration Cmdlet 會停用本機電腦上的會話設定,以防止所有使用者使用會話設定在本機計算機上建立使用者管理的會話(PSSessions)。 這是一個進階 Cmdlet,其設計目的是由系統管理員用來管理其使用者的自定義會話設定。
從 PowerShell 3.0 開始,Disable-PSSessionConfiguration Cmdlet 會將會話組態的 enabled 設定WSMan:\localhost\Plugins\<SessionConfiguration>\Enabled設為 False。
在 PowerShell 2.0 中,Disable-PSSessionConfiguration Cmdlet 會將 Deny_All 專案新增至一或多個已註冊工作階段設定的安全性描述項。
如果沒有參數,Disable-PSSessionConfiguration 會停用 Microsoft.PowerShell 組態,這是會話所使用的預設組態。 除非使用者指定不同的組態,否則會有效防止本機和遠端使用者建立任何連線到計算機的會話。
若要停用電腦上的所有工作階段設定,請使用 Disable-PSRemoting。
範例
範例 1:停用預設組態
此範例會停用 Microsoft.PowerShell 會話設定。
Disable-PSSessionConfiguration
範例 2:停用所有已註冊的會話設定
此範例會停用計算機上所有已註冊的會話設定。
Disable-PSSessionConfiguration -Name *
範例 3:依名稱停用會話設定
此範例會停用名稱開頭為 Microsoft 的所有會話組態。 Force 參數會隱藏來自 Cmdlet 的所有使用者提示。
Disable-PSSessionConfiguration -Name Microsoft* -Force
範例 4:使用管線停用會話設定
此範例會停用 MaintenanceShell 和 AdminShell 會話設定。 管線運算子 (|) 會將 Get-PSSessionConfiguration 的結果傳送至 Disable-PSSessionConfiguration。
Get-PSSessionConfiguration -Name MaintenanceShell, AdminShell | Disable-PSSessionConfiguration
範例 5:停用會話設定的效果
此範例顯示執行 Disable-PSSessionConfiguration 前後的許可權,以及停用會話設定的效果。
PS> Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto
Name Permission
---- ----------
MaintenanceShell BUILTIN\Administrators AccessAllowed
microsoft.powershell BUILTIN\Administrators AccessAllowed
microsoft.powershell32 BUILTIN\Administrators AccessAllowed
PS> Disable-PSSessionConfiguration -Name MaintenanceShell -Force
PS> Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto
Name Permission
---- ----------
MaintenanceShell Everyone AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell BUILTIN\Administrators AccessAllowed
microsoft.powershell32 BUILTIN\Administrators AccessAllowed
PS> New-PSSession -ComputerName localhost -ConfigurationName MaintenanceShell
[localhost] Connecting to remote server failed with the following error message : Access is denied.
For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed
備註
停用組態並不會阻止您使用 Set-PSSessionConfiguration Cmdlet 變更組態。 它只會防止使用組態。
參數
-Confirm
在執行 Cmdlet 之前,提示您進行確認。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | cf |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Force
強制命令執行,而不要求使用者確認。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Name
指定要停用的工作階段組態名稱陣列。 輸入一或多個組態名稱。 允許使用通配符字元。 您也可以使用管線將包含群組態名稱或工作階段組態物件的字串傳送至 Disable-PSSessionConfiguration。
如果您省略此參數,Disable-PSSessionConfiguration 會停用 Microsoft.PowerShell 會話設定。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | 0 |
| 必要: | False |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | True |
| 來自剩餘引數的值: | False |
-NoServiceRestart
用來防止重新啟動 WSMan 服務。 不需要重新啟動服務以停用設定。
參數屬性
| 類型: | 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,您必須使用 [以 系統管理員身分執行] 選項