Update! (22-Nov-2014) Updated the script to include a prompt for which distribution point group to use and a couple of minor improvements
Have you ever wanted to have the capability of scheduling a package distribution in ConfigMgr to occur at a specific date / time? Or perhaps you want to monitor your package distributions an receive an email when it has completed? Well now you can!
As a ConfigMgr administrator, I sometimes want to schedule my package distributions to take place outside of office hours, especially with very large packages like windows images. I don’t want to consume a lot of bandwidth during working hours, so I prefer to start them at a time when the bandwidth I consume has the least impact on the sites I am distributing from and to. Sure I can use bandwidth limiting on the distribution point, but I don’t want to restrict bandwidth for all my distributions during working hours, only the really big ones, so out of hours is a better option.
Additionally I want to monitor my distributions to see when they have completed and how long they take. There is a nice tool in the ConfigMgr 2012 R2 toolkit called ‘Distribution Point Job Queue Manager’, but there is no facility to receive a notification when a distribution has completed. Instead you must continually refresh it, which I can’t do if I’m scheduling a distribution out of hours.
To meet this need, I prepared a PowerShell script available from the Technet Gallery that will do either of the following things:
- Schedule the distribution of a new ConfigMgr package (equivalent to ‘Distribute Content‘ in the ConfigMgr console), monitor it, and send an email when the distributions have finished.
Schedule the update of a package content to a distribution point group (equivalent to ‘Update Distribution Points‘ in the ConfigMgr Console), monitor it, and send an email when the distributions have finished.
Monitor an already-running distribution and send an email when the distributions have finished.
The script will work for any package type, eg standard package, driver package, task sequence packages, software update packages, application content packages, OS images, boot images, OS installer packages.
It works by creating a ‘scheduled job’ in PowerShell, which will start at the time you specify. The scheduled job is a PowerShell script that will start the package distribution, monitor the status of the distributions in WMI, then send an email when all the active distributions for that package are complete. It will also email you if a distribution fails, although ConfigMgr will retry a failed distribution up to 99 times, so it will continue to monitor it for completion.
Update Distribution Points Example
Let’s take a look at an example. In this case I’ve updated the source files for a deployment type called ‘Uninstall Java‘ in my ‘Java‘ application, and I want to update the distribution points with the new content.
Let’s run the script. The first thing it asks for is what I want to do. If I’ve created a new package or application and I want to distribute it to my distribution point group, I choose option . If I’ve updated source files for an existing package or application and I want to update the distribution points with the new content, I choose . If I’ve already started a package distribution and I simply want to monitor it, I choose . In this case, i’m choosing .
Now it asks me for an email address to send the distribution monitor email notifications to.
Next I can enter the date and time that I want the package distribution to start. You can enter enter any date and/or time format that your regional settings will understand. For example, I can enter 22:00 to start my distribution today at 10pm. Or I can enter 25/12/14 15:00 to start my distribution at 3pm on Christmas day in the UK time zone. Pretty sure that won’t impact the network! If I want to distribute the package now, I simply hit Enter, and it will be scheduled in 3 minutes from now.
Next it asks me for the name of the package or application I want to distribute. It will then check the ConfigMgr WMI to validate whether a package or application exists with that name, and what type of package it is.
Since it is an application I must also enter which deployment type I want to distribute content for:
Great, now my distribution job has been scheduled and will run at the set time.
Let’s see what email notifications we get. First, we get a notification that the distribution has started:
Sometimes a distribution to one or more of the distribution points may fail the first time. If it does, ConfigMgr will retry it up to 99 more times before giving up. The script will continue to monitor the distribution, but we will get a notification that one or more the distributions has failed, and will be retried. This is good to know as the distribution will likely take longer than usual because of a failure.
Once the distribution has completed on all distribution points, we get an email summarizing the distribution.
Let’s look at another example. in this case, I’ve already distributed content for a package called ‘Retain Corporate Client‘, and I want to monitor the distribution for its completion.
In this case, I’m asked similar questions to before, but then it will tell me what package distributions are currently active, and ask me which one I want to monitor. There is only one at the moment, and I enter the Package ID that it gives me. Then my monitor job is scheduled to run in 2 minutes from now.
I get much the same emails as before:
Configuring the Script
To run the script, you should enter the following email variables at the top of the script. These will probably not change so you can just enter them one time and that’s it.
The script must also be run as administrator. This is required to create scheduled jobs. If you are not running it as administrator, you will be notified.