'need to change the site code in line Set WbemServices = loc.ConnectServer( ,"root\SMS\site_XXX")
'script takes input from a text file collectionslist.txe, having collection names.
Option Explicit
On Error Resume Next
Dim loc
Dim Collection
Dim Collections
Dim strCollection
Dim strCollectionID
Dim Advertisement
Dim Advertisements
Dim objFSO
Dim objFile
Dim WbemServices
Const ForReading = 1
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer( ,"root\SMS\site_XXX")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("collectionslist.txt", ForReading)
Do Until objFile.AtEndOfStream
strCollection = objFile.ReadLine
Set Collections = WbemServices.ExecQuery("select * from SMS_Collection where name like '%" & strCollection & "%'")
For Each Collection In Collections
strCollectionID = Collection.CollectionID
Wscript.Echo "Collection : " + Collection.Name
Set Advertisements = WbemServices.ExecQuery("select * from SMS_Advertisement where CollectionID = """ & strCollectionID & """")
For Each Advertisement in Advertisements
Wscript.Echo "Advertisement : " & Advertisement.AdvertisementName
Advertisement.Delete_
Next
On Error Goto 0
Collection.Delete_
Next
Loop
objFile.Close
'script takes input from a text file collectionslist.txe, having collection names.
Option Explicit
On Error Resume Next
Dim loc
Dim Collection
Dim Collections
Dim strCollection
Dim strCollectionID
Dim Advertisement
Dim Advertisements
Dim objFSO
Dim objFile
Dim WbemServices
Const ForReading = 1
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer( ,"root\SMS\site_XXX")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("collectionslist.txt", ForReading)
Do Until objFile.AtEndOfStream
strCollection = objFile.ReadLine
Set Collections = WbemServices.ExecQuery("select * from SMS_Collection where name like '%" & strCollection & "%'")
For Each Collection In Collections
strCollectionID = Collection.CollectionID
Wscript.Echo "Collection : " + Collection.Name
Set Advertisements = WbemServices.ExecQuery("select * from SMS_Advertisement where CollectionID = """ & strCollectionID & """")
For Each Advertisement in Advertisements
Wscript.Echo "Advertisement : " & Advertisement.AdvertisementName
Advertisement.Delete_
Next
On Error Goto 0
Collection.Delete_
Next
Loop
objFile.Close
Hello, What are the changes that I need to do to run this script on my environment? When I tried, I got the error " VBScript runtime error: Object required: ''
ReplyDeleteThanks