I am looking to find a script that we currently use in SCCM 2007 but doesn't seem to work in 2012. This script goes out and finds all the collections a machine is a direct member of then removes it from them. I have been struggling to get this work in 2012 and thought I would see if anyone else has made something to do this.
Here is my current working script: Names and site codes have been changed to protect the innocent ;) Param( $machineName ) #Get the resource ID $Resource = Get-WmiObject -Namespace "root\sms\site_111" -ComputerName <servername> -Class SMS_R_SYSTEM -Filter "Name='$machineName'" #Loop through all the resourceID's found ForEach ($res in $Resource) { Write-Host "Found ResourceID: " $Res.ResourceID $Memberships = Get-WmiObject -Namespace "root\sms\site_111" -ComputerName <servername> -Class SMS_CollectionMember_a -filter "ResourceID='$($Res.ResourceId)'" Write-Host $Memberships #Loop through all the membership rules for that resourceID ForEach ($Membership in $Memberships) { #Only list direct membership types. if ($Membership.IsDirect){ Write-Host "Found direct collection membership: " $Membership.CollectionID $Collection = Get-WmiObject -Namespace "root\sms\site_111" -ComputerName <servername> -Class SMS_COLLECTION -Filter "CollectionID='$($Membership.CollectionID)'" $Collection.Get() #grab the direct membership rule $Rule = ($Collection.CollectionRules | Where-Object {$_.ResourceID -eq $res.ResourceID}) #delete the rule $nul = $Collection.DeleteMembershipRule($Rule) } } } Thanks you, ............................................................................................................................. Jason King Please consider the environment before printing this email. ________________________________ CONFIDENTIALITY NOTICE: This email contains information from the sender that may be CONFIDENTIAL, LEGALLY PRIVILEGED, PROPRIETARY or otherwise protected from disclosure. This email is intended for use only by the person or entity to whom it is addressed. If you are not the intended recipient, any use, disclosure, copying, distribution, printing, or any action taken in reliance on the contents of this email, is strictly prohibited. If you received this email in error, please contact the sending party by reply email, delete the email from your computer system and shred any paper copies. Note to Patients: There are a number of risks you should consider before using e-mail to communicate with us. See our Privacy & Security page on www.henryford.com for more detailed information as well as information concerning MyChart, our new patient portal. If you do not believe that our policy gives you the privacy and security protection you need, do not send e-mail or Internet communications to us.