powershell - 将用户添加到 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)
谢谢和欢呼,
乌诺
解决方案
我认为这是因为基本类型发生了变化。** 出口前 **
$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)
** 为我工作 - 谢谢 :) 正是我想要的。
推荐阅读
- scala - 使用 Scalatest 测试 ScalikeJDBC Publisher
- php - 是否可以使用 EntityManagerInterface 类基于两个外键创建查询?
- java - 特定位置的recycleview setadapter
- pypy - 在 Windows 10 Enterprise 上运行 PyPy3 的问题
- json - 为什么我的 JSON 函数无法识别我的 .createElement 按钮?
- sql - SQL 存在于 TableA 或 TableB 中
- r - 具有多个类的 pivot_longer 会导致错误(“No common type”)
- python - IMDbPy:如何捕捉 IMDbDataAccessError?
- excel - 从一个表复制到另一个表 (VBA)
- javascript - 如何获取 PHP 日期和当前 JS 日期之间经过的时间