gpt4 book ai didi

powershell - 如何使用WMI和Powershell将更改保存到Windows组

转载 作者:行者123 更新时间:2023-12-02 23:45:31 24 4
gpt4 key购买 nike

使用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:提供程序无法执行尝试的操作

最佳答案

作为documentedDescription对象的Win32_Group属性是只读的。使用ADSI WinNT provider代替:

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

关于powershell - 如何使用WMI和Powershell将更改保存到Windows组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com