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 [1]. 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 [2]. If I’ve already started a package distribution and I simply want to monitor it, I choose [3]. In this case, i’m choosing [2].
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.
Package Distribution Monitor Example
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.
Enjoy 🙂
Sweet Script:
Couple of thoughts if you don’t mind…for next revision. (Mind you I haven’t actually tried it in my environment yet, so you might have already addressed)
1. Ability to target Specific DP Groups…at different times
2. Will it deal with Old style packages, specifically the SUP distribution packages, or the OSD Image Packages
Reason I am thinking this is these are large packages so my network team wants them sent off hours in each Geography(we divide the world in thirds).
I might try to hack up the script myself and if I get there I’ll provide back my changes.
Hey…so couple things:
1. You have a BUG in the line of Code where you check the value of the distribution Type:
Line 68 in the Copy of the Script I downloaded reads:
if ($distype -eq “1” -or $DistType -eq “2”)
it Should be
if ($distType -eq “1” -or $DistType -eq “2”)
2. I hacked in support for the Distribution Point Group being specified might be a good thing to support, Most environments need the ability to target different groups at different times.
I changed the $DPG Reference to:
$DefaultDPG = “Default Distribution Points” # DefaultDistribution Point Group
And added the following just after the Check of the Distribution Type: (Between Lines 68 and 69)
do
{
try
{
[string]$DPG = Read-host “Enter Distribution Group to Target for Default of all DPs”
}
catch {}
}
until (($DPG -like ‘*DPs*’) -or ($DPG -eq ”))
if ($DPG -eq “”)
{
$DPG = $DefaultDPG
}
Hey Bill,
Thanks for your comments and for pointing out the misspelled variable! I have updated the script and added some code to prompt for which distribution point group to use (this is only relevant for first-time distributions).
You can use it for any package type in ConfigMgr, as described in the blog. It is especially useful for OS images for sure.
I like your solution for getting the DP group names directly instead of my freeform hack. I had been intending to look into how to pull the DP names, but never got around to it. Thanks for updating and taking my comments. Frustrating how many of these tools are out there, and people make comments to the creators, but they never get any updates.
Gentlemen. Thank you so much! This is amazing. Any experience with Pull DPs and using this? My plan was to schedule it to send to my main Data Center DPs, then wait a few hours to let it settle. Then schedule all the DPs in that area to get the file via Pull DP. *fingers crossed*.