SCCM 2012 PowerShell Cmdlets – Staggering Content Validation Schedule

Author by Matt Herman

I recently had a customer with a large number of Distribution Points who wanted to use Content Validation, but did not want to all of them on the same schedule hitting the Primary Site Server at the same time.  You could always get your clicking finger loose and have at it through the console, but personally I would rather have a script do the work for me.  Here’s what I came up with for the script.

################################################################################
#
#  Name: DistributionPointConfig-ContentValidationSchedule.ps1
#
#  AUTHOR: Matt Herman & Aaron Fields @ Concurrency, Inc
#  
#################################################################################
   
    #Modules
    Import-Module "D:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" -Force
    
    # Global Variables
    $ScriptPath = ($MyInvocation.MyCommand.Path) | Split-Path 
    $SiteCode = "SITE_CODE"    
    $LOGFile = $ScriptPath +  "\Logs\ContentValidationSchedule.txt" 
    
    #Enter SCCM PSProvider
    Set-Location "SITE_CODE:\"
    
    $DPs = Get-CMDistributionPoint -SiteSystemServerName DP*.YourDomain.Com
 
    # Loop Through All DPs    
    Foreach ($DP in $DPs)   
   
    {
    #Get DP Name
    $DPName = $DP.NetworkOSPath.replace("\\", "")
      
    #Log the Start of Each DP
    Write-Output "Starting $DPName - $(Get-Date)" | Out-File $LOGFile -Append
 
    #Enable Contnet Validation
    Set-CMDistributionPoint -SiteCode $SiteCode -SiteSystemServerName  $DPName -EnableValidateContent 1
 
    #Create New Content Validation Schedule Based On Store Number
    IF ($DPName -like 'DP???[01]*') {$Sched = New-CMSchedule -DayOfWeek Saturday -Start "08/01/2014 12:00 AM" -RecurCount 1 ; $Sched | Out-File $LOGFile -Append} 
    ELSEIF ($DPName -like 'DP???[23]*') {$Sched = New-CMSchedule -DayOfWeek Saturday -Start "08/01/2014 01:00 AM" -RecurCount 1 ; $Sched | Out-File $LOGFile -Append}
    ELSEIF ($DPName -like 'DP???[45]*') {$Sched = New-CMSchedule -DayOfWeek Saturday -Start "08/01/2014 02:00 AM" -RecurCount 1 ; $Sched | Out-File $LOGFile -Append}
    ELSEIF ($DPName -like 'DP???[67]*') {$Sched = New-CMSchedule -DayOfWeek Saturday -Start "08/01/2014 03:00 AM" -RecurCount 1 ; $Sched | Out-File $LOGFile -Append}
    ELSEIF ($DPName -like 'DP???[89]*') {$Sched = New-CMSchedule -DayOfWeek Saturday -Start "08/01/2014 04:00 AM" -RecurCount 1 ; $Sched | Out-File $LOGFile -Append}
    
    #Apply Schedule to DP
    Set-CMDistributionPoint -SiteCode $SiteCode -SiteSystemServerName $DPName -ValidateContentSchedule $Sched | Write-Output "Error: $Error" Out-File $LOGFile -Append
 

    } #End of Forech Loop

First, I’m loading the SCCM Module into Powershell, setting up variables and connecting to the SCCM site.  Then I’m using Get-CMDistributionPoint to load all the DPs into an array.  From there, I go into a loop to set Content Validation on each DP.

Inside the loop, I start by reformatting the DP name for use in my commands.  Then I use Set-CMDistributionPoint to enable Content Validation on each DP.  Next, I setup a variable to use the New-CMSchedule command to set the schedule based on the sixth character of the DP name.  To wrap-up, I ‘m using Set-CMDistributionPoint again to apply the schedule to the DP.

This script can take a few minutes to run depending on the speed of your server and the number of DPs in your environment.  However, you can monitor the script’s log file with CMTrace to make sure it is working properly.

Author

Matt Herman

Technical Architect