How To Restore the 'All Systems' Collection

The default All Systems collection is special in the sense that it has a unique Collection ID (SMS00001). In case you end up 'accidentally' deleting the All Systems collection from your SMS/SCCM console, the only way to restore it with the default Collection ID is programmatically. Here's a script that does that, along with adding the Collection Query and the Update Schedule.

 strSMSServer = "."
 strParentCollID = "COLLROOT"
 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"
 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 = "All Systems"
 newCollection.AddMembershipRule objQueryRule
  
 'Add the Schedule
 Set Token = objSMS.Get("SMS_ST_RecurInterval")
 Token.DaySpan = 1
 newCollection.RefreshSchedule = Array(Token)
 newCollection.RefreshType = 2
 newCollection.Put_
  
 'Refresh Collection Membership
 newCollection.RequestRefresh False

Run the script as follows on the Site Server, and you should have the default collection back:
cscript.exe RecreateAllSystemsCollection.vbs

IMPORTANT: Using the example above works in my lab, however information in this post is provided "AS IS" with NO Warranties, or Support.

Vinay Pamnani | Support Engineer

Comments

  • Anonymous
    September 02, 2010
    Nice one...