forked from Kaidja/ConfigMgrSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
How to create an Include Rule
22 lines (17 loc) · 1.04 KB
/
How to create an Include Rule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$CollectionName = "OSD Bare Metal"
$IncludeCollectionName = "New Dev Col"
$ParentCollection = Get-WmiObject -Namespace 'ROOT\sms\Site_PS1' -Class SMS_Collection -Filter "Name='$CollectionName'"
$SubCollection = Get-WmiObject -Namespace 'ROOT\sms\Site_PS1' -Class SMS_Collection -Filter "Name='$IncludeCollectionName'"
$VerifyDependency = Invoke-WmiMethod -Namespace 'ROOT\sms\Site_PS1' -Class SMS_Collection -Name VerifyNoCircularDependencies -ArgumentList @($ParentCollection.__PATH,$SubCollection.__PATH,$null)
If($VerifyDependency){
#Read Lazy properties
$ParentCollection.Get()
#Create the new rule
$NewRule = ([WMIClass]"\\Localhost\root\SMS\Site_PS1:SMS_CollectionRuleIncludeCollection").CreateInstance()
$NewRule.IncludeCollectionID = $SubCollection.CollectionID
$NewRule.RuleName = $SubCollection.Name
#Commit changes and initiate the collection evaluator
$ParentCollection.CollectionRules += $NewRule.psobject.baseobject
$ParentCollection.Put()
$ParentCollection.RequestRefresh()
}