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
)的“已启用” 设置设置为 False。
在 PowerShell 2.0 中,Disable-PSSessionConfiguration
cmdlet 向一个或多个已注册的会话配置的安全描述符添加 Deny_All 条目。
如果没有参数,Disable-PSSessionConfiguration
将禁用 Microsoft.PowerShell 配置(用于会话的默认配置)。 除非用户指定其他配置,否则将有效地阻止本地用户和远程用户创建连接到计算机的任何会话。
若要禁用计算机上的所有会话配置,请使用 Disable-PSRemoting
。
此示例禁用 Microsoft.PowerShell 会话配置。
Disable-PSSessionConfiguration
此示例禁用计算机上的所有已注册会话配置。
Disable-PSSessionConfiguration -Name *
此示例禁用名称以 Microsoft
开头的所有会话配置。
Force 参数禁止来自 cmdlet 的所有用户提示。
Disable-PSSessionConfiguration -Name Microsoft* -Force
此示例禁用 MaintenanceShell 和 AdminShell 会话配置。 管道运算符(|
)将 Get-PSSessionConfiguration
的结果发送到 Disable-PSSessionConfiguration
。
Get-PSSessionConfiguration -Name MaintenanceShell, AdminShell | Disable-PSSessionConfiguration
此示例显示运行 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 更改配置。 它仅阻止使用配置。
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
强制命令运行而不要求用户确认。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
指定要禁用的会话配置的名称数组。 输入一个或多个配置名称。 允许使用通配符。 还可以通过管道将包含配置名称或会话配置对象的字符串传递给 Disable-PSSessionConfiguration
。
如果省略此参数,Disable-PSSessionConfiguration
禁用 Microsoft.PowerShell 会话配置。
类型: | String[] |
Position: | 0 |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | True |
用于防止重启 WSMan 服务。 无需重启服务来禁用配置。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
显示 cmdlet 运行时会发生什么情况。 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
Microsoft.PowerShell.Commands.PSSessionConfigurationCommands
可以通过管道将会话配置对象传递给此 cmdlet。
可以通过管道将包含会话配置名称的字符串传递给此 cmdlet。
None
此 cmdlet 不返回任何输出。
此 cmdlet 仅在 Windows 平台上可用。
若要运行此 cmdlet,必须使用 以管理员身份运行 选项启动 PowerShell。