Automating Long-Running MDT 2010 Tasks
There are a few operations in the MDT 2010 Deployment Workbench that can take a while. We’ve done our best to optimize those processes, but in many cases they will still take a good amount of time to complete. While you could certainly start an operation in one Deployment Workbench and then open another Deployment Workbench so that you can continue working, it would be even better to schedule these long-running tasks so that they run automatically, ideally when you are sleeping and when there aren’t any active Lite Touch deployments going on.
Fortunately, since the Deployment Workbench is now PowerShell-based you can now write simple PowerShell scripts to perform these activities. The following three samples show you how to do it.
Sample #1: Updating a deployment share
The “Update Deployment Share” process takes the latest changes made to the deployment share (bootstrap.ini updates, new drivers, new patches, script changes, etc.) and updates the Windows PE boot images (WIM files and ISOs if requested). Depending on the extent of the changes, this process might take 15-30 minutes (depending on the I/O performance of the machine – it’s definitely an I/O-bound process, especially for the WIM and DISM actions performed by this process). The following script will automate the process:
Start-Transcript C:\Scripts\UpdateDeploymentShare.log
# Connect to the deployment share
Add-PSSnapIn Microsoft.BDD.PSSnapIn
New-PSDrive DS002 MDTProvider \\MTN-SERVER\Distribution$# Update the deployment share
Update-MDTDeploymentShare -Path DS002: -VerboseStop-Transcript
Save that as “UpdateDeploymentShare.ps1” and schedule it to run nightly using the Windows Task Scheduler. The action command line required (assuming you saved the script in C:\Scripts) would be:
PowerShell.exe -File C:\Scripts\UpdateDeploymentShare.ps1
Make sure you have configured PowerShell to allow script execution, e.g. “Set-ExecutionPolicy RemoteSigned”. And be sure to update the deployment share path above, as I’m sure your deployment share isn’t at \\MTN-SERVER\Distribution$.
Sample #2: Updating media content
If you haven’t figured out where we moved “media deployment points” in MDT 2010, they now have their own node: look under the “Advanced Configuration” node in Deployment Workbench and you’ll see the new “Media” node. You can create one or more media definitions there, specifying what content should be included in the media (by specifying the selection profile to use when copying content to the media), Windows PE settings to use, whether to generate an ISO, etc.
The “Update Media Content” action is what actually does the work, copying the specified content, generating boot images, and (optionally) generating ISOs. The following script automates this process, looping through each of the media items that you have defined:
Start-Transcript C:\Scripts\UpdateMedia.log
# Connect to the deployment share
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction SilentlyContinue
New-PSDrive DS002 MDTProvider \\MTN-SERVER\Distribution$# Process each of the media items
Get-ChildItem DS002:\Media | % { Update-MDTMedia -Path "DS002:\Media\$($_.Name)" -Verbose }Stop-Transcript
Save that as “UpdateMedia.ps1” and schedule it to run nightly using the Windows Task Scheduler. The action command line to run this (assuming again that the script is saved in C:\Scripts) would be:
PowerShell.exe -File C:\Scripts\UpdateMedia.ps1
Again, be sure to edit the path above, as \\MTN-SERVER\Distribution$ is the path to my deployment share, not yours.
Sample #3: Updating linked deployment shares
Network deployment points, now called linked deployment shares, also have a new home in MDT 2010 Deployment Workbench: look for them under “Advanced Configuration”, in the “Linked Deployment Shares” folder. These too use selection profiles to specify what content should be replicated, so arrange your folder structures as needed and create a selection profile that includes the required folders.
The “Replicate Content” action performs the actual replication, copying the content specified in the configured selection profile. It can also optionally generate the boot images for the linked deployment share (although if you want to configure the Windows PE settings for that remote deployment share you’ll need to open that deployment share in the Deployment Workbench to make the changes). The following script initiates the same process:
Start-Transcript C:\Scripts\UpdateLinkedDS.log
# Connect to the deployment share
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction SilentlyContinue
New-PSDrive DS002 MDTProvider \\MTN-SERVER\Distribution$# Process each of the linked deployment share items
Get-ChildItem "DS002:\Linked Deployment Shares" | % { Update-MDTLinkedDS -Path "DS002:\Linked Deployment Shares\$($_.Name)" -Verbose }Stop-Transcript
One last time: edit the path above to specify the path (either a local path or a UNC) to your deployment share. To run this using the Windows Task Schedule, specify an action command line like so:
PowerShell.exe -File C:\Scripts\UpdateLinkedDS.ps1
Comments
Anonymous
January 14, 2011
Shouldn't the scheduled task command be "powershell.exe -command <path>" rather than "powershell.exe -file <path>"?Anonymous
January 31, 2015
I just wanted to say that I found your "Update Media Content" Script very useful. Modified it a little to my scenario, but working great. Thanks for the useful tips!