Redistribute Failed Content in SCCM 2012

Author by Matt Herman

A common task when rolling out new Distribution Points in SCCM is to redistribute failed content.  David O’Brien has a great PowerShell script, found here, to redistribute all failed content in your site.  The script works well, but I was working on a project deploying hundreds of Pull Distribution Points, so I wanted at little more control on what is getting redistributed.

I decided to have the script read a CSV file, in the same directory as the script, to control what DPs had content redistributed.  A copy of the script is below.

################################################################################
#
#
#  Name: RedistributeFailedContent.ps1
#
#  AUTHOR: Matt Herman & Aaron Fields, Concurency Inc
#
#  VERSION HISTORY:
#
#  1.0 8/29/14 Adapted from David O'Brien's script found here: 
#       http://www.david-obrien.net/2013/11/20/redistribute-failed-packages-configmgr-dps/
#  
#
#################################################################################
 
#Variables
$ScriptPath = ($MyInvocation.MyCommand.Path) | Split-Path 
$SiteCode = "XXX" #Insert Site Code
 
#Import data from CSV
$DPs = Import-Csv ($ScriptPath + '\RedistributeFailedContent.csv')
 
#Loop through all entries from CSV
Foreach ($DP in $DPs)
    {
 
   $ServerName = $DP.FQDN
 
    $failures = $null
    # Find all content with State = 1, State = 2 or State = 3, see http://msdn.microsoft.com/en-us/library/cc143014.aspx
    $failures = Get-WmiObject -Namespace root\sms\site_$SiteCode -Query "SELECT * FROM SMS_PackageStatusDistPointsSummarizer WHERE ServerNALPath like '%$ServerName%' and (State = 1 or State = 2 Or state = 3)"
    if ($failures -eq $null)
        {
            "No failed content distribution."
        }
    else
        {
            foreach ($failure in $failures)
                {
                    # Get the distribution points that content wouldn't distribute to
            $DistributionPoints = Get-WmiObject -Namespace root\sms\site_$SiteCode -Query "SELECT * FROM SMS_DistributionPoint WHERE SiteCode='$($failure.SiteCode)' AND  PackageID='$($failure.PackageID)'"
                    foreach ($DistributionPoint in $DistributionPoints)
                        {
                            #check if we are really looking at the correct Distribution Point
                if ($DistributionPoint.ServerNALPath -eq $failure.ServerNALPath)
                                {
                                    # Use the RefreshNow Property to "Refresh Distribution Point", see http://msdn.microsoft.com/en-us/library/hh949735.aspx
                    $DistributionPoint.RefreshNow = $true
                                    $DistributionPoint.put()
                                }
                        }
                }
        }

    }

Author

Matt Herman

Technical Architect