基于机器variables的SCCM设备集合成员身份

我不确定这是否是完全可能的,但是我正在努力编写WQL查询语句,使我可以根据机器variables来填充SCCM设备集合。

例如:名为“TestVM-01”的设备有一个名为“PatchGroup”的机器variables,其值为“Hour1”。 我希望名为“Hour1”的设备集合dynamic地填充PatchGroupvariables设置为Hour1的任何设备。

我首先努力通过PowerShell和WMI查询设备variables,因为SMS_MachineVarible类是SMS_MachineSettings的惰性属性,因此您必须通过完整path调用对象。

在Powershell / WMI中,我可以用这样的东西来查询它

(([wmi]"\\SCCM-LAB\root\sms\site_001:SMS_Machinesettings.ResourceID=11111111").machinevariables | where name -eq "PatchGroup").value 

如果您查询SMS_MachineSettings而不指定对象的完整path,它将返回MachineVariables属性为空

任何人都可以告诉我,我将如何编写WQL,以从SMS_Resource类“其中PatchGroup = x”拉对象的列表?

单个WMI查询将不起作用,默认的“创build设备集合向导”也不起作用。 懒属性是另一个对象实例的属性和值的列表,我们需要在VBscript和PowerShell中使用SwbemServices.ExecQuery()COM接口,或者在PowerShell中使用Get-WmiObject来提取数据。

我将使用像PowerShell Script这样的方法来生成计算机ResourceID列表,并使用这些ID使用内置CM cmdlet创buildDirectRule集合。 每次我将在我要使用这个集合之前运行这个脚本。

看下面的脚本块获取ResourceID列表:

 $cmdletLocaltion = 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' $sitecode = 'P01:' Import-Module $cmdletLocaltion cd $sitecode #-Lines to cleanup all the directcollection membership rules -# $machineObject = Get-WmiObject -Namespace root\sms\site_p01 -Class sms_machinesettings Foreach ($machine in $machineObject) { $Path = $machine.__PATH $machine = [wmi]"$path" foreach ($varvalue in $machine.MachineVariables) { if (($varvalue.name -eq 'PatchGroup') -and ($varvalue.Value -eq 'Hour1')) { $machine.ResourceID #--line here to add to collection membership--# } } }