四处搜索,我创建了一个脚本,用于向现有集合添加查询类型规则,或多或少像:
$CommonParameters = @{
ComputerName = "servername"
Namespace = 'root\sms\site_111'
}
$CollName="Devices_AppName_FR_01.00.00_R2.000_Standard"
$TargetCollType=2
$computer="servername"
$Codesite="111"
$PCColl=GWMI @CommonParameters -Query "SELECT CollectionID FROM SMS_Collection WHERE Name = '$NewName' AND CollectionType = '$TargetCollType'"
$PCColl.get()
$PCRule = ([WMIClass]"\\$($computer)\root\sms\site_$($Codesite):SMS_CollectionRuleQuery"). CreateInstance()
$PCRule.QueryExpression="select * from SMS_R_System where SMS_R_System.ResourceDomainORWorkgroup = 'DN' and SMS_R_System.SystemOUName = 'F.Q.D.N./Desktops/Something'"
$PCRule.RuleName = "test"
$PCColl.AddMembershipRule($PCRule)
$PCRule = ([WMIClass]"\\$($computer)\root\sms\site_$($Codesite):SMS_CollectionRuleQuery"). CreateInstance()
$PCRule.QueryExpression="select * from SMS_R_System where SMS_R_System.ResourceDomainORWorkgroup = 'DN' and SMS_R_System.SystemOUName = 'F.Q.D.N./Desktops/SomethingElse'"
$PCRule.RuleName = "test2"
$PCColl.AddMembershipRule($PCRule)
$PCSchedule = ([WMIClass]"\\$($computer)\Root\sms\site_$($Codesite):SMS_ST_RecurInterval").Cre ateInstance()
$PCSchedule.DaySpan = "7"
$PCSchedule.StartTime = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime((Get-Date))
$PCColl.RefreshSchedule=$PCSchedule
$PCColl.Put()
因此,综合来说,获取集合,添加2个新的成员资格,更新计划并提交更改。
事后检查收集,我可以看到附表被正确修改(DaySpan到7天),但似乎没有添加成员规则。
经过不同的修改和检查后,以下代码有效:
$CommonParameters = @{
ComputerName = "servername"
Namespace = 'root\sms\site_111'
}
$CollName="Devices_AppName_FR_01.00.00_R2.000_Standard"
$TargetCollType=2
$computer="servername"
$Codesite="111"
$PCColl=GWMI @CommonParameters -Query "SELECT CollectionID FROM SMS_Collection WHERE Name = '$NewName' AND CollectionType = '$TargetCollType'"
$PCColl.get()
$PCSchedule = ([WMIClass]"\\$($computer)\Root\sms\site_$($Codesite):SMS_ST_RecurInterval").CreateInstance()
$PCSchedule.DaySpan = "7"
$PCSchedule.StartTime = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime((Get-Date))
$PCColl.RefreshSchedule=$PCSchedule
$PCColl.Put()
$PCRule = ([WMIClass]"\\$($computer)\root\sms\site_$($Codesite):SMS_CollectionRuleQuery").CreateInstance()
$PCRule.QueryExpression="select * from SMS_R_System where SMS_R_System.ResourceDomainORWorkgroup = 'DN' and SMS_R_System.SystemOUName = 'F.Q.D.N./Desktops/Something'"
$PCRule.RuleName = "test"
$PCColl.AddMembershipRule($PCRule)
$PCRule = ([WMIClass]"\\$($computer)\root\sms\site_$($Codesite):SMS_CollectionRuleQuery").CreateInstance()
$PCRule.QueryExpression="select * from SMS_R_System where SMS_R_System.ResourceDomainORWorkgroup = 'DN' and SMS_R_System.SystemOUName = 'F.Q.D.N./Desktops/SomethingElse'"
$PCRule.RuleName = "test2"
$PCColl.AddMembershipRule($PCRule)
因此,综合来说,获取集合,更新计划,提交更改并添加2个新的成员资格。
我担心的是不能理解为什么我不必使用.Put()方法提交。 这对我来说似乎是合乎逻辑的(必须提交更改),尤其是阅读this。