首页 > 解决方案 > 将用户添加到 WMI 控件并通过 SDDL / powershell 编辑配置

问题描述

我正在尝试创建一个脚本,将用户添加到 root 和所有子命名空间,并授予他

Execute Methods, Enable Account, Remote Enable and Read Security

通过脚本的权限,就像您在 wmimgmt 中手动执行的操作一样。
我尝试使用:导出 wmimgmt 设置并使用:(如在此处找到)
$SidHelper = New-Object System.Management.ManagementClass Win32_SecurityDescriptorHelper $SdList = @($null) $(Get-WMIObject -Namespace "root" -Class __SystemSecurity).PsBase.InvokeMethod("GetSD",$SdList) [System.Management.Automation.PSSerializer]::Serialize($SdList) | Set-Content sdlist.txt
将它们导入回来时, 会给出正确的权限,但我要添加的不是用户的 SID,而是未知用户。 1.你们知道为什么脚本没有按预期运行吗? 2. 除了上面提到的脚本之外,您知道如何通过脚本在 wmimgmt 中添加用户并授予他权限吗?
$SdList = [System.Management.Automation.PSSerializer]::Deserialize($(Get-Content sdlist.txt)) $SidHelper = New-Object System.Management.ManagementClass Win32_SecurityDescriptorHelper $RootSecurity = $(Get-WMIObject -Namespace "root" -Class __SystemSecurity) $RootSecurity.PsBase.InvokeMethod("SetSd",$SdList)



谢谢和欢呼,
乌诺

标签: powershellwmiwmic

解决方案


我认为这是因为基本类型发生了变化。** 出口前 **

$sdlist.getType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

** 反序列化后 **

$sdlist2.getType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ArrayList                                System.Object

** 尝试使用下面的[System.Array]进行类型转换**

$SdList = [System.Array] [System.Management.Automation.PSSerializer]::Deserialize($(Get-Content sdlist.txt))
$SidHelper = New-Object System.Management.ManagementClass Win32_SecurityDescriptorHelper
$RootSecurity = $(Get-WMIObject -Namespace "root" -Class __SystemSecurity)
$RootSecurity.PsBase.InvokeMethod("SetSd",$SdList)

** 为我工作 - 谢谢 :) 正是我想要的。


推荐阅读