Disable-PSSessionConfiguration

在本地電腦上停用會話設定。

語法

Default (預設值)

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

Description

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

指令 Disable-PSSessionConfiguration 長會停用本地電腦的會話設定,阻止所有使用者使用會話設定在本地電腦上建立由使用者管理的會話(PSSessions)。 這是一個進階指令小程式,設計給系統管理員用來管理使用者自訂的會話設定。

從 PowerShell 3.0 開始,Disable-PSSessionConfigurationcmdlet 會將會話設定WSMan:\localhost\Plugins\<SessionConfiguration>\Enabled的 Enabled 設定()設為 False。

在 PowerShell 2.0 中, Disable-PSSessionConfiguration cmdlet 會在一個或多個註冊會話設定的安全描述符中加入 一個Deny_All 條目。

若無參數,Disable-PSSessionConfiguration 會使 Microsoft失效。PowerShell 設定,是用於會話的預設設定。 除非使用者指定不同的設定,否則本地與遠端使用者都實質上無法建立任何連接電腦的會話。

要停用電腦上的所有會話設定,請使用 Disable-PSRemoting.

範例

範例 1:停用預設設定

此範例禁用了 Microsoft。PowerShell session configuration.

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

Note

停用設定並不阻止你用 Set-PSSessionConfiguration cmdlet 更改設定。 它只會阻止使用該配置。

參數

-Confirm

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

參數屬性

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

參數集

(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 session configuration.

參數屬性

類型:

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

你可以將一個 session configuration 物件管道連接到這個 cmdlet。

String

你可以將包含會話組名稱的字串輸入這個 cmdlet。

輸出

None

此 Cmdlet 不會傳回任何輸出。

備註

此 Cmdlet 僅適用於 Windows 平臺。

要執行這個 cmdlet,你必須透過以 管理員身份執行 選項啟動 PowerShell。