拒绝访问本地计算机上的会话配置。

语法

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

说明

Disable-PSSessionConfiguration cmdlet 阻止所有计算机用户在会话中使用会话配置。这是一个高级 cmdlet,供系统管理员为其用户管理自定义会话配置时使用。

Disable-PSSessionConfiguration cmdlet 向一个或多个已注册会话配置的安全描述符添加“全部拒绝”设置。因此,您可以注销、查看和更改这些配置,但不能在会话中使用它们。

如果不使用参数,Disable-PSSessionConfiguration 将禁用 Microsoft.PowerShell 配置,即用于会话的默认配置。除非用户指定了其他配置,否则这将有效地阻止本地和远程用户创建连接到计算机的任何会话。

若要禁用计算机上的所有会话配置,请使用 Disable-PSRemoting。

参数

-Force

禁止显示所有用户提示。默认情况下,提示您确认每个操作。

是否为必需?

false

位置?

named

默认值

False

是否接受管道输入?

false

是否接受通配符?

false

-Name <string[]>

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

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

是否为必需?

false

位置?

1

默认值

Microsoft.PowerShell

是否接受管道输入?

true (ByValue, ByPropertyName)

是否接受通配符?

true

-Confirm

在执行命令之前提示您进行确认。

是否为必需?

false

位置?

named

默认值

是否接受管道输入?

false

是否接受通配符?

false

-WhatIf

描述如果执行该命令会发生什么情况(无需实际执行该命令)。

是否为必需?

false

位置?

named

默认值

是否接受管道输入?

false

是否接受通配符?

false

<CommonParameters>

此 cmdlet 支持通用参数:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。有关详细信息,请参阅 about_Commonparameters.

输入和输出

输入类型是指可通过管道传递给 cmdlet 的对象的类型。返回类型是指 Cmdlet 所返回对象的类型。

输入

Microsoft.PowerShell.Commands.PSSessionConfigurationCommands#PSSessionConfiguration, System.String

可以通过管道将会话配置对象或包含会话配置名称的字符串传递给 Disable-PSSessionConfiguration。

输出

None

此 cmdlet 不返回任何对象。

说明

若要在 Windows Vista、Windows Server 2008 以及更高版本的 Windows 上运行此 cmdlet,您必须使用“以管理员身份运行”选项启动 Windows PowerShell。

示例 1

C:\PS>Disable-PSSessionConfiguration

说明
-----------
此命令禁用 Microsoft.PowerShell 会话配置。






示例 2

C:\PS>disable-pssessionConfiguration -name *

说明
-----------
此命令禁用计算机上的所有已注册会话配置。






示例 3

C:\PS>disable-pssessionConfiguration -name Microsoft* -force

说明
-----------
此命令禁用名称以“Microsoft”开头的所有会话配置。该命令使用 Force 参数禁止显示所有用户提示。






示例 4

C:\PS>Get-PSSessionConfiguration -name MaintenanceShell, AdminShell | Disable-PSSessionConfiguration

说明
-----------
此命令禁用 MaintenanceShell 和 AdminShell 会话配置。

该命令使用管道运算符 (|) 将 Get-PSSessionConfiguration 命令的结果发送到 Disable-PSSessionConfiguration。






示例 5

C:\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

C:\PS> Disable-PSSessionConfiguration -name MaintenanceShell -force

C:\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

C:\PS> Set-PSSessionConfiguration -name MaintenanceShell -MaximumReceivedDataSizePerCommandMB 60

ParamName            ParamValue
---------            ----------
psmaximumreceived... 60

"Restart WinRM service"
WinRM service need to be restarted to make the changes effective. Do you want to run the command "restart-service winrm"?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y


C:\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_Troubl
eshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionOpenFailed

说明
-----------
此示例说明禁用会话配置的效果。

第一条命令使用 Get-SessionConfiguration 和 Format-Table cmdlet 只显示会话配置对象的 Name 和 Permission 属性。使用这种表格式便于查看对象值。结果显示允许 Administrators 组的成员使用会话配置。

第二条命令使用 Disable-PSSessionConfiguration cmdlet 禁用 MaintenanceShell 会话配置。该命令使用 Force 参数禁止显示所有用户提示。

第三条命令重复第一条命令。结果显示您仍可以获取表示 MaintenanceShell 会话配置的对象,即使拒绝所有用户访问该对象也是如此。“AccessDenied”条目优先于安全描述符中的所有其他条目。

第四条命令使用 Set-PSSessionConfiguration cmdlet 将 MaintenanceShell 会话配置上的 MaximumDataSizePerCommandMB 设置增大为 60。结果显示该命令成功执行,即使拒绝所有用户访问该配置也是如此。

第五条命令尝试在会话中使用 MaintenanceShell 会话配置。它使用 New-PSSession cmdlet 创建新会话,并使用 ConfigurationName 参数指定 MaintenanceShell 配置。由于拒绝该用户访问该配置,因此结果显示 New-PSSession 命令失败。






另请参阅




目录