Using an Automatic Deployment Rule in ConfigMgr 2012 helps automating your Software Update deployments a lot. In the case where you configure the ADR to run at a specific time after Patch Tuesday, lets say on Wednesday evening at 23.00 PM, and you’d want the deployment deadline time to be 3 days ahead on Saturday at 02.00 AM, you’ll see that it’s not possible within the ConfigMgr console. I’ve at least not found an easy way to do so. Let’s try to illustrate it a bit more in detail.

In this case I have an ADR for my lab environment clients that is set to be run at 12/1/2013 11:10 AM.

67_1

On the Deployment Schedule tab, I’ve configured the Installation Deadline to be 7 days ahead. The effective installation deadline time for this deployment would be on the 12/8/2013 3:10 PM. I’ve not yet found out why ConfigMgr is adding a few extra hours to the installation deadline time, but I’m assuming that it’s for allowing distribution to happen across all Distribution Points.

67_2

How can we change this installation deadline time then to be set to a time and date we’d like? It’s actually not that hard. We’d have to write a few lines of either PowerShell or another scripting language to get the desired results. Let’s take a look at how we can accomplish this with PowerShell.

The script that we’ll use is the following:

[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)"
        }
    }
}

Save this script as e.g. Set-ADRDeploymentTime.ps1. The script itself accepts a few parameters. Here’s a description of each of them:

  • 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 7 days ahead, at 02:00 AM and only on the deployments created yesterday. Execute the script by running the following command line elevated and as a ConfigMgr Full Administrator:

.\Set-ADRDeploymentTime.ps1 -SiteServer CAS01.contoso.com -SiteCode CAS -CreationTimeDays 1 -DeadlineDays 7 -DeadlineHours "0200"

67_3

NOTE! It’s important that you remember the quotation marks around the DeadlineHours, or the script will fail.

If we now take a look at the properties of the deployment, we can see that installation deadline has changed to what we set it to:

67_4

Why should you change this? Well it’s all about control. If you’re familiar with how maintenance windows work you’ll probably think to yourself, why don’t I just schedule the ADR to be evaluated at a certain time instead so the installation deadline time is set within the maintenance window. Well, you can of course do so, but if that time period happens to be when you’re server load is at it’s peak you can use this method instead. And in order to automate this process, create a scheduled task that is configured to run at a certain amount of time after the ADR evaluation schedule.

Nickolaj Andersen
Principal Consultant and Enterprise Mobility MVP. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows deployments and Automation. In 2015 Nickolaj was awarded as PowerShell Hero by the community for his script and tools contributions. Author of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService and a frequent speaker at user groups.

(206)

comments
  • Greg Mackinnon
    Posted at 18:39 February 7, 2014
    Greg Mackinnon
    Reply
    Author

    Henk:

    Thanks for this post. It saved me a lot of time!

    In case it is helpful to anyone, I posted a variation of this script that instead updates all Software Update Group Deployments to become due on a date specified by an input parameters:
    http://blog.uvm.edu/jgm/2014/02/07/sccm-deployment-deadlines/

    I also added some annotations to help in deciphering the annoying date formats used with WMI objects.

    • Nickolaj
      Posted at 23:04 February 7, 2014
      Nickolaj
      Reply
      Author

      Hi Greg,

      I believe that you’ve confused me with Henk, my name is Nickolaj and this is my blog 🙂

      I’d be glad if you’d update your post with my name instead. Really cool script you put together though, I bet that others will find it very useful.

      Regards,
      Nickolaj

  • Leave a Reply