Monday, 12 March 2012

Script to remove the list of packages from DPs in SCCM

This script will remove the packages given in text file listofpackagesToDelete.txt to that DP


Option Explicit
'On Error Resume Next

Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList

Dim WbemServices
Dim loc

Dim DPs, DP

Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer( , "root\SMS\site_999")

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("listofpackagesToDelete.txt", ForReading)


Do Until objTextFile.AtEndOfStream
    'read the next line
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , "    ")

    'arrServiceList(0) = packageid, arrServiceList(1) = DP

    Set DPs = wbemServices.ExecQuery("Select * From SMS_DistributionPoint WHERE PackageID='" & arrServiceList(0) & "' AND SiteCode = '" & arrServiceList(1) & "'")

    For Each DP In DPs
        Wscript.Echo  DP.ServerNALPath
        DP.Delete_
    Next
Loop

No comments:

Post a Comment