SCCM: How to Restore the All Systems Collection in SCCM/SMS

When I got into the office this morning an email came in from one of our technicians. The issue was that he couldn’t see the All Systems collection anymore and wanted me to put it back. Since I know I didn’t do this, I took a look at Status Message Queries to see what happened. I specifically looked at “Collections Created, Modified, or Deleted” to see who the culprit was and when the deletion happened. Once I figured out that yes, All Systems was in fact deleted, I ran the following VBScript (copy this text to a text file and save it as all_systems.vbs and run it on your site server):

strSMSServer = “.”
strParentCollID = “COLLROOT”
‘This example creates the collection in the collection root.
‘Replace COLLROOT with the CollectionID of an existing collection to make the new collection a child.

strCollectionName = “All Systems”
strCollectionComment = “This is the All Systems Collection.”
Set objLoc = CreateObject(“WbemScripting.SWbemLocator”)
Set objSMS = objloc.ConnectServer(strSMSServer, “root\sms”)
Set Results = objSMS.ExecQuery (“SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true”)

For each Loc in Results
If Loc.ProviderForLocalSite = True Then
Set objSMS = objLoc.ConnectServer(Loc.Machine, “root\sms\site_” & Loc.SiteCode)
End if
Next

Set newCollection = objSMS.Get(“SMS_Collection”).SpawnInstance_()

‘Create new “All Systems” collection
newCollection.Name = “All Systems”
newCollection.OwnedByThisSite = True
newCollection.Comment = strCollectionComment
newCollection.CollectionID = “SMS00001”
path = newCollection.Put_

‘Set the Relationship
Set newCollectionRelation = objSMS.Get(“SMS_CollectToSubCollect”).SpawnInstance_()
newCollectionRelation.parentCollectionID = strParentCollID
newCollectionRelation.subCollectionID = (“SMS00001”)
newCollectionRelation.Put_

‘Add the Query Rule
Query = “SELECT * FROM SMS_R_SYSTEM”
Set objQueryRule = objSMS.Get(“SMS_CollectionRuleQuery”).SpawnInstance_
objQueryRule.QueryExpression = Query
objQueryRule.RuleName = “AllSystems”
newCollection.AddMembershipRule objQueryRule

The collection was remade and all the objects are there like they should be. Now I need to lock all collections down so our techs don’t delete them anymore.

This entry was posted in sccm. Bookmark the permalink.

3 Responses to SCCM: How to Restore the All Systems Collection in SCCM/SMS

  1. rbalsley says:

    Fixed an issue with this script and smart quotes. This was causing issues when running the script.

  2. JSschwering says:

    Thx for this Script

  3. Pingback: How to Restore the All Systems Collection in SCCM/SMS « LUGN

Leave a Reply

Your email address will not be published. Required fields are marked *