-
Notifications
You must be signed in to change notification settings - Fork 7
/
How to create a Direct Membership rule
36 lines (29 loc) · 1.55 KB
/
How to create a Direct Membership rule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Example 1
$ResourceName = "Server100"
$CollectionName = "OSD Bare Metal"
$ResourceQuery = Get-WmiObject -Namespace "Root\SMS\Site_PS1" -Class SMS_R_SYSTEM -Filter "Name = '$ResourceName'"
$CollectionQuery = Get-WmiObject -Namespace "Root\SMS\Site_PS1" -Class SMS_Collection -Filter "Name = '$CollectionName' and CollectionType='2'"
#Read Lazy properties
$CollectionQuery.Get()
#Create new direct membership rule
$NewRule = ([WMIClass]"\\Localhost\root\SMS\Site_PS1:SMS_CollectionRuleDirect").CreateInstance()
$NewRule.ResourceClassName = "SMS_R_System"
$NewRule.ResourceID = $ResourceQuery.ResourceID
$NewRule.Rulename = $ResourceQuery.Name
#Commit changes and initiate the collection evaluator
$CollectionQuery.CollectionRules += $NewRule.psobject.baseobject
$CollectionQuery.Put()
$CollectionQuery.RequestRefresh()
#Example 2
$ResourceName = "Server100"
$CollectionName = "OSD Bare Metal"
$ResourceQuery = Get-WmiObject -Namespace "Root\SMS\Site_PS1" -Class SMS_R_SYSTEM -Filter "Name = '$ResourceName'"
$CollectionQuery = Get-WmiObject -Namespace "Root\SMS\Site_PS1" -Class SMS_Collection -Filter "Name = '$CollectionName' and CollectionType='2'"
#Create new direct membership rule
$NewRule = ([WMIClass]"\\Localhost\root\SMS\Site_PS1:SMS_CollectionRuleDirect").CreateInstance()
$NewRule.ResourceClassName = "SMS_R_System"
$NewRule.ResourceID = $ResourceQuery.ResourceID
$NewRule.Rulename = $ResourceQuery.Name
#Commit changes and initiate the collection evaluator
$CollectionQuery.AddMemberShipRule($NewRule)
$CollectionQuery.RequestRefresh()