Forcing a refresh on failed packages with PowerShell

Sometimes for various reasons packages seems to fail getting to some distribution points and even if it retries 100 times it won’t fix itself. Often by doing a manual refresh on the package will fix the problem since that forces the whole package to be reloaded and not just a delta upgrade as the built in updater tries to use.

The manual process of doing this is first identifying the package with problem, I usually use the report called “All active package distributions” (number 136). Then you have to locate the package, expand the “Distribution Points” node, right click the DP with issues and choose “Refresh Distribution Point”.

But this can be a tedious task if you have a lot of failing packages or if you have a lot of packages and you are not sure where to find them (since there is no search function in ConfigMgr 2007).

So I wrote a script in PowerShell to fix it for you, one note though. When this is run all failing packages will be triggered with a Refresh and the Server will start resending the full package so if you are concerned about traffic only run this script after business hours.

The script needs to be edited with the site code of your current site!

[sourcecode language='powershell'  wraplines='true' htmlscript='true' padlinenumbers='true' highlight='' firstline='1']
$SiteCode = "ABC"

#Get all packages which are reporting bad installation, check http://msdn.microsoft.com/en-us/library/cc143014.aspx for valid State codes
$pkgs = Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -Query "Select * From SMS_PackageStatusDistPointsSummarizer Where State = 2 OR state = 3"

#Make sure $pkgs is not empty
if ($pkgs) {}
else
{
	#Split them up with foreach and process each individualy
    foreach ($pkg in $pkgs)
    {
        #Get all the distributionpoint objects for the failing packages, needs to be split up in to parts since i cant get ServerNALPath to work in the Select query, the
        #    special charactares in ServerNALPath seems to mess up the query
        $dps = Get-WmiObject -Namespace "root\SMS\Site_$($SiteCode)" -Query "Select * From SMS_DistributionPoint WHERE SiteCode='$($pkg.SiteCode)' AND PackageID='$($pkg.PackageID)'"
        foreach ($dp in $dps)
        {
            #Compare ServerNALPath with the failing package's ServerNALPath to make sure we force the refresh on the correct DP
            If ($dp.ServerNALPath -eq $pkg.ServerNALPath)
            {
                # Force the refresh and call the Put() method to make it happen
                $dp.RefreshNow = $true
                $dp.Put()
            }
        }
    }
}
[/sourcecode]

And it can be downloaded here:

email

Written by , Posted .
  • Andreas Nordlander

    Any change you could make a similar script for SCCM 2012?