Disable-PSSessionConfiguration

禁用本地计算机上的会话配置。

语法

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

说明

此 cmdlet 仅在 Windows 平台上可用。

Disable-PSSessionConfiguration cmdlet 可禁用本地计算机上的会话配置,从而防止所有用户使用该会话配置在本地计算机上创建用户管理的会话 (PSSessions)。 这是一个高级 cmdlet,旨在供系统管理员为其用户管理自定义会话配置时使用。

从 PowerShell 3.0 开始,Disable-PSSessionConfiguration cmdlet 将会话配置 (WSMan:\localhost\Plugins\<SessionConfiguration>\Enabled) 的 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 之前进行确认。

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

强制运行命令而不要求用户确认。

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Name

指定要禁用的会话配置的名称数组。 输入一个或多个配置名称。 允许使用通配符。 你还可以通过管道将包含配置名称的字符串或会话配置对象传递给 Disable-PSSessionConfiguration

如果省略此参数,则 Disable-PSSessionConfiguration 将禁用 Microsoft.PowerShell 会话配置。

Type:String[]
Position:0
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:True

-NoServiceRestart

用于防止重启 WSMan 服务。 无需重启服务来禁用配置。

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

可以通过管道将会话配置对象传递给此 cmdlet。

String

可以将包含会话配置名称的字符串通过管道传递给此 cmdlet。

输出

None

此 cmdlet 不返回任何输出。

备注

此 cmdlet 仅在 Windows 平台上可用。

若要运行此 cmdlet,必须使用“以管理员身份运行”选项启动 PowerShell