-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathHow to create an Exclude Rule
More file actions
22 lines (17 loc) · 1.04 KB
/
How to create an Exclude Rule
File metadata and controls
22 lines (17 loc) · 1.04 KB
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"
$ExclusionCollectionName = "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='$ExclusionCollectionName'"
$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 new rule
$NewRule = ([WMIClass]"\\Localhost\root\SMS\Site_PS1:SMS_CollectionRuleExcludeCollection").CreateInstance()
$NewRule.ExcludeCollectionID = $SubCollection.CollectionID
$NewRule.RuleName = $SubCollection.Name
#Commit changes and initiate the collection evaluator
$ParentCollection.CollectionRules += $NewRule.psobject.baseobject
$ParentCollection.Put()
$ParentCollection.RequestRefresh()
}