Removing a retired DP from all your packages


When you remove an SMS 2003 Distribution Point (DP) from a site, and existing packages have been distributed to this DP, those packages may not be removed.  If you look at that package in the admin console you will notice that the the type has changed from “Server” to “Unknown”.  The Package Status will also show a type of nothing instead of “Server”.


To properly remove these you can use the Manage Distribution Points Wizard to uncheck the DP before removing it as a site system.  This can be a tedious task if you have hundreds or thousands of packages.  An alternative to doing this manually is to use the SDK.  I have attached a script that automates this task.  Note, the script does validate whether your DP still exists.  If you have already removed the DP as a site system and want to clean it up then you will have to remove the call to ValidDP().  Take note that if you do this then Distribution Manager will attempt to remove the package files from the DP so if it doesn’t exist on the network then you will get errors in the distmgr.log and Distribution Manager component.


‘Rslaten 03/2005

On Error Resume Next

WScript.Echo “”
WScript.Echo “SMSDPClean v1.3”
WScript.Echo “Usage: cscript.exe SMSDPClean <CenSiteServerName> <NameOfDP>”
WScript.Echo “Example: cscript.exe SMSDPClean.vbs myCentralSiteServer myDistributionPoint”
WScript.Echo “”

Dim SMSSiteServer, SMSNameSpace, oLocator, oServices, bDone

‘Get Args, add error checking here if needed
SMSSiteServer = WScript.Arguments(0)
DP = WScript.Arguments(1)

‘Get SMS namespace
SMSNameSpace = GetSMSNameSpace(SMSSiteServer)

‘Connect to SMS namespace
Set oLocator = CreateObject(“WbemScripting.SWbemLocator”)
Set oServices = oLocator.ConnectServer(SMSSiteServer, SMSNameSpace,,,,,128)
If Err.number <> 0 Then
WScript.Echo “Error connecting to “ &SMSNameSpace& ” on “ &SMSSiteServer& “: “ &Err.Number
Set oLocator = Nothing
Set oServices = Nothing
WScript.Quit
End If

‘Call main procedure
PackageLoop

‘Loop until async task is done
Do While not bDone
WScript.Sleep 1000
Loop

Set oLocator = Nothing
Set oServices = Nothing
WScript.Quit

‘Functions
””””””””””””””””””””’

‘GetSMSNameSpace Function

””””””””””””””””””””’

Function GetSMSNameSpace(SiteServer)
On Error Resume Next
Dim
colNameSpaceQuery, refitem, refWMI
Set refWMI = GetObject(“winMgmts:\\” &SiteServer&“\root\sms”)
If Err.number <> 0 Then
WScript.Echo “Error connecting to SMS namespace on “ &SiteServer
WScript.Quit
End If
Set
colNameSpaceQuery = refWMI.ExecQuery(“select * from SMS_ProviderLocation”)
For Each refitem in colNameSpaceQuery
GetSMSNameSpace = refitem.NamespacePath
Next
Set colNameSpaceQuery = Nothing
Set refitem = Nothing
Set refWMI = Nothing
End Function

””””””””””””””””””””’

‘ValidDP Function

””””””””””””””””””””’

Function ValidDP(DP, SiteCode)
On Error Resume Next
Dim
SysRes, start, finish, tempDP
ValidDP = False
Set SysRes = oServices.ExecQuery(“select * from sms_sci_sysresuse where SiteCode = ‘” &SiteCode& “‘”)
For each res in SysRes
start = InStr(res.NALPath,“=\\”) + 3
finish = InStr(res.NALPath,“]MSWNET”) – 2
tempDP = mid(res.NALPath,start,finish-start)
If (UCase(tempDP) = UCase(DP)) and (res.RoleName = “SMS Distribution Point”) Then
Set SysRes = Nothing
ValidDP = True
Exit Function
End If
Next

Set SysRes = Nothing
End Function

””””””””””””””””””””’

‘PackageLoop SubRoutine

””””””””””””””””””””’

Sub PackageLoop
On Error Resume Next
Dim
sinkcol, retValuecol
bDone = False
Set sinkcol = wscript.CreateObject(“WbemScripting.SWbemSink”,“SINKCOL_”)
retValuecol = oServices.ExecQueryAsync(sinkcol,“SELECT * FROM SMS_DistributionPoint”)
If Err.Number <> 0 Then
WScript.Echo “Error running query:” &err.description
WScript.Quit
End If
End Sub
Sub
SINKCOL_OnObjectReady(objDP, objAsyncContext)
On Error Resume Next
Dim
start, finish, tempDP
start = InStr(objDP.ServerNALPath,“=\\”) + 3
finish = InStr(objDP.ServerNALPath,“]MSWNET”) – 2
tempDP = mid(objDP.ServerNALPath,start,finish-start)
If UCase(tempDP) = UCase(DP) Then
WScript.Echo “Found “ &DP& ” on “& objDP.SiteCode& ” linked to package “ &objDP.PackageID
If ValidDP(DP, objDP.SiteCode) Then
WScript.Echo “Validated “ &DP& ” for site “ &objDP.SiteCode
objDP.Delete_()
If Err.number <> 0 Then
WScript.Echo “Failed to delete “ &DP& ” from package “ &objDP.PackageID& ” on site “ &objDP.SiteCode
WScript.Echo “Error = “ &Err.number& ” – “ &Err.Description
Else
WScript.Echo “Successfully deleted “ &DP& ” from package “ &objDP.PackageID& ” on site “ &objDP.SiteCode
End If
Else

WScript.Echo DP& ” is not specified as a distribution point on site “ &objDP.SiteCode
End If
End If
End Sub
Sub
SINKCOL_OnCompleted(iHResult, objErrorObject, objAsyncContext)
bDone = True
End Sub

DPClean.zip

Comments (10)

  1. Link to SMS/MOM WebLog by Russ Slaten : Removing a retired DP from all your packages Thanks to Todd Hemsell

  2. stippelt says:

    Hi,

    a realy good script. But I’ve got a problem.

    The Server is no more online and now the distribution Manager wants to delete the packages. What can I do to?

  3. Russ Slaten says:

    This is why I’ve got that call to validdp in the script.  To stop distmgr from reporting errors once you’re in a situation where the DP is offline and you’ve removed it from the UI you must do some manual cleanup of the PKG files in the distmgr.box.  If you’re in this situation I would either reproduce the situation in the lab and ensure that any fixes you implement do not have a negative affect or open a case with customer support so we can assist.

  4. When you remove an SMS 2003 Distribution Point (DP) from a site, and existing packages have been distributed

  5. starpc says:

    I’ve a DP thats no longer online, however it is still listed in SMS as a DP,  will this script work to remove the packages or will I get errors in the distribution manager?

  6. rhastings80 says:

    Hi,  Wondering if you know if this will work on SCCM 2007?

    Thanks,

    Rob

  7. wanafly says:

    Hi Russ,

    Really helpful script. But can you tell me, will this work on SCCM 2007 and SCCM 2012 ?

  8. Russ Slaten says:

    I have not tested this script with SCCM, but I have heard of people using it at least with SCCM 2007.

  9. JDelvasto says:

    The DP was removed from console with out first removing packages.  In the comments it says to remove the call to ValidDP.  How can I accomplish this.  Your help is greatly appreciated.

  10. Russ Slaten says:

    Hi, you can just set the following line to True instead of False: ValidDP = False