SCCM Script to Delete Specific Collections and Associated Advertisements

System Center, Technology Add comments

Finding our console growing with numerous collections and advertisements related to single-instance software distributions to a named device, I wanted a process to follow that would permit automated “cleansing” of the console. The script should not only remove the collections, but also the associated advertisements. After searching the net for something to repurpose, I ended up putting this one together from scratch.

It requires the sitecode be changed and a command line argument for the search criteria (i.e. wscript c:\windows\DelCollAdv.vbs “System :”). Also, because I’m not specifying the remote server name, it has to be run local to the SMS provider or the “Set WbemServices” line needs to be updated to include the remote host name.

NOTE: USE AT YOUR OWN RISK. TEST IN A NON-PRODUCTION ENVIRONMENT. THE AUTHOR IS NOT RESPONSIBLE FOR DAMAGES.

————————————–

Begin Copy Below

————————————–

Option Explicit

Dim loc
Set loc = CreateObject(“WbemScripting.SWbemLocator”)

Dim WbemServices
Set WbemServices = loc.ConnectServer( ,”root\SMS\site_ABC”)

Dim Collection
Dim Collections

Dim strCollection
Dim strCollectionID

Dim Advertisement
Dim Advertisements

strCollection = Wscript.Arguments(0)

Set Collections = WbemServices.ExecQuery(“select * from SMS_Collection where name like ‘%” & strCollection & “%’”)

For Each Collection In Collections
strCollectionID = Collection.CollectionID
‘MsgBox “Got collection: ” + Collection.CollectionID

Set Advertisements = WbemServices.ExecQuery(“select * from SMS_Advertisement where CollectionID = “”" & strCollectionID & “”"”)
‘On Error Resume Next
For Each Advertisement in Advertisements
MsgBox “About to Delete: ” & Advertisement.AdvertisementName & “. To cancel, kill the wscript process from TaskMgr.”
Advertisement.Delete_
Next
‘On Error Goto 0
Collection.Delete_
Next

————————————–

End Copy Above

————————————–

One Response to “SCCM Script to Delete Specific Collections and Associated Advertisements”

  1. SCCM Script to Delete Specific Collections and Associated Advertisements | System Center Guide - Rod Trent at myITforum.com Says:

    [...] SCCM Script to Delete Specific Collections and Associated Advertisements | System Center Guide Filed under: Scripting, System Center, ConfigMgr 2007 [...]

Leave a Reply

You must be logged in to post a comment.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in