【问题标题】:How to save changes to Windows group using WMI and Powershell如何使用 WMI 和 Powershell 将更改保存到 Windows 组
【发布时间】:2014-06-05 18:33:57
【问题描述】:

使用 Powershell,我通过 WMI 检索 Windows 组。然后我尝试修改属性并更新对象,但失败了(请参阅下面的错误消息)。怎么了 ?

$group = Get-WmiObject Win32_Group -Filter ("Domain='{0}' and Name='{1}'" -f $env:ComputerName, $groupName)
$group.Description = $newDescription
$group.Put()

错误: System.Management.Automation.MethodInvocationException:使用“0”参数调用“Put”的异常:“提供者无法尝试操作”---> System.Management .ManagementException:提供者无法进行尝试的操作

【问题讨论】:

    标签: powershell wmi


    【解决方案1】:

    作为documentedWin32_Group 对象的Description 属性是只读的。请改用ADSI WinNT provider

    $group = [adsi]"WinNT://$env:COMPUTERNAME/$groupName,group"
    $group.Description = $newDescription
    $group.SetInfo()
    

    【讨论】:

    • 非常感谢,它有效!我没想到 Description 属性可能是只读的,我专注于 put 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 2014-12-27
    相关资源
    最近更新 更多