Quantcast
Channel: ConfigMgr (SCCM) – All about Microsoft Endpoint Manager
Viewing all articles
Browse latest Browse all 252

#SCCM / #Configmgr Script to delete packages from Assigned DPs

$
0
0

Long ago ,written SCCM report to list packages not used for 6 months as part of Package Archival process http://eskonr.com/2012/11/sccm-configmgr-package-archival-process-cleanup-activity/ .This report tells you to take further action to clean or move to Archive folder to wait for some more months before it goes for Deletion.

What next ? Delete these packages from Assigned DPs to get some disk space ?

You may find several scripts to do this task on the internet but, i  find this is easy for me to get this activity done.

Identify list of package which you want to remove ,pipe them to notepad .You can do more customizations if needed.

Script to delete packages from its assigned Distribution Points.

strComputer =inputBox("Please Enter the SMS provider OR Site where the packages are created" , "SCCM Server name")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set packages=fso.OpenTextFile("C:\PACKAGESTODELETE.txt",1,true)
Set objoutputfile=fso.OpenTextFile("C:\DP_results.txt",2,true)

Do While packages.AtEndOfLine <> True
    ‘read the next line
    package = packages.Readline

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\SMS\site_CEN")
if err.number<>0 then
    msgbox "server connection failed"
    wscript.quit
end if
Set colItems = objWMIService.ExecQuery("SELECT * FROM SMS_DistributionPoint where packageid=’" & Package & "’")
For Each objItem in colItems
        ‘Wscript.Echo "ServerNALPath: " & objItem.ServerNALPath
objoutputfile.WriteLine ( package & vbTab & " will be deleteting from" & VBTAB & objItem.ServerNALPath)

objitem.Delete_

If Err.number <> 0 Then

objoutputfile.WriteLine ( "Failed to delete" & vbTab & package & "from" &  vbTab & objItem.ServerNALPath)
      End If
    Next

loop

msgbox "Done"

Note: Please Replace the quotes.


Viewing all articles
Browse latest Browse all 252

Trending Articles