SCCM – PowerShell – Modify ADRs Deadline Time

email me

In recent SCCM builds, Microsoft has introduced Automatic Deployment Rules (ADR’s) which have the ability to automatically approve updates and deploy them. You use this method for deploying monthly updates, along with some third party updates. It’s a nice enhancement, the only problem is…there are so many windows to click through, just to find out some settings aren’t available after the initial creation of the rule (Microsoft, say it ain’t so). PowerShell can get around that. Using PS, you can make direct changes to the ADR right from ISE or the PS console.

 
The Script

[CmdletBinding()]
param(
[parameter(Mandatory=$true)]
$SiteServer,
[parameter(Mandatory=$true)]
$SiteCode,
[parameter(Mandatory=$true)]
[int]$CreationTimeDays,
[parameter(Mandatory=$true)]
[int]$DeadlineDays,
[parameter(Mandatory=$true)]
[ValidateScript({$_.Length -eq 4})]
$DeadlineHours
)
 
$CurrentDate = (Get-Date).AddDays(-$CreationTimeDays).ToShortDateString()
$Deadline = ([System.Management.ManagementDateTimeConverter]::ToDmtfDateTime((Get-Date).AddDays($DeadlineDays))).Split(".").SubString(0,8)[0]
$Time = "$($DeadlineHours)00"
 
$ADRClientDeployment = Get-WmiObject -Namespace "root\sms\site_$($SiteCode)" -Class SMS_UpdateGroupAssignment -ComputerName $SiteServer
foreach ($Deployment in $ADRClientDeployment) {
    $CreationDate = $Deployment.ConvertToDateTime($Deployment.CreationTime).ToShortDateString()
    $DeploymentName = $Deployment.AssignmentName
    if ($CreationDate -gt $CurrentDate) {
        Write-Output "Deployment to be modified: `n$($DeploymentName)"
        try {
            $Deployment.EnforcementDeadline = "$($Deadline)$($Time).000000+***"
            $Deployment.Put() | Out-Null
            if ($?) {
                Write-Output "`nSuccessfully modified deployment`n"
            }
        }
        catch {
            Write-Output "`nERROR: $($_.Exception.Message)"
        }
    }
}

 

Script Name: Change-ADRTime.ps1

Parameters:

  • SiteServer
    Should be a NetBIOS or FQDN of your site server
  • SiteCode
    Enter the site code of the specified site server
  • CreationTimeDays
    The number specified here will determine what deployments will be modified depending on the creation time of each deployment
  • DeadlineDays
    Specify a number of days ahead you would want the new installation deadline time to be
  • DeadlineHours
    Specified in 4 digits, e.g. “1400” is equal to 02:00 PM. It’s important that you specify value for this parameter within quotations

Let’s say that we’d want to change the installation deadline time to 5 days ahead, at 01:00 PM and only on the deployments created yesterday.
Command Line

As an SCCM Admin, run

.\Change-ADRTime.ps1 -SiteServer sccm.DOMAIN.com -SiteCode 001 -CreationTimeDays 1 -DeadlineDays 5 -DeadlineHours "1300"