Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. $computer = $env:COMPUTERNAME
  2. $ErrorActionPreference = "Continue"
  3.  
  4. $ResourceID = (Get-WmiObject -Class SMS_R_System -Namespace root\SMS\site_SITECODE -ComputerName #SITESERVER# | Where-Object {$_.name -eq "$computer"}).resourceid
  5.  
  6. $CollectionIDs = (Get-WmiObject -Class SMS_DeploymentInfo -Namespace root\SMS\site_SITECODE -ComputerName #SITESERVER# | Where-Object {$_.DeploymentType -eq "7" -and $_.collectionname -ne "All Unknown Computers"}).CollectionID
  7.  
  8. $DirectRule = [wmiclass]("\\#SITESERVER#\ROOT\SMS\site_SITECODE:SMS_CollectionRuleDirect")
  9.  
  10. $DirectRule.Properties["ResourceClassName"].Value = "SMS_R_System"
  11. $DirectRule.Properties["ResourceID"].Value = "$ResourceID"
  12. $DirectRule.Properties["RuleName"].Value = "$computer"
  13.  
  14. foreach ($CollectionID in $CollectionIDs) {
  15. (Get-WmiObject -Class SMS_Collection -Namespace root\SMS\site_SITECODE -ComputerName #SITESERVER# | Where-Object {$_.collectionid -eq "$CollectionID"}).DeleteMembershipRule($DirectRule)
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement