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.
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.
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"
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:
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.
Hello Nickolaj,
Do you have and suggestions for targeting one ADR, versus all ADR’s in the site?
Thanks!
Hi Mark,
Not sure why you’d want to do that (do you want to set the same time or different times for them?), but extending the script to retrieve all instances of ADR’s shouldn’t be that hard. When you’ve retrieved all instances, simply just loop through them one at a time and make the changes.
How many ADR’s do you have that needs to be changed?
Regards,
Nickolaj
We have several ADR’s for different patching groups, including different dev and production environments. I find the current deadline determination a bit clunky and unreliable. I’m looking for a powershell script that lets me target one ADR deployment at a time. I’m trying to make this easier on other team members who may need to step in.
Hi Mark,
Sorry for the late reply. Please contact me offline at [email protected] and we could discuss the options.
Regards,
Nickolaj
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:
https://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.
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