ConfigMgr – Automating Pre-Staging of Task Sequence (Driver Packs)

Sep 7, 2018 | | Say something

Pre-staging content associated with a OSD Task Sequence in ConfigMgr can be a very tiring and repetitive task. If we had to use the ConfigMgr console to create a pre-staged content package, we would have to use at least 16 mouse-clicks and some typing to get the pre-staged package completed. And if we have multiple packages, applications, driver packs, boot images, etc to pre-stage, it can take a very long time doing one by one. Not just the mouse-clicks, but also knowing exactly where each and every package or application is located in the console can also be a huge headache. Well it was for me!

But if you don’t like a lot of mouse-clicking and typing, and would rather spend your time and energy on something more exciting, then we can automate a lot of the pre-staging content steps. Follow the steps outlined below:

Firstly we need to create our destination folder structure where the pre-staged content would be saved to.

Create a folder structure as per example: D:\Pre-Staged\DriverPacks

Create a text file in this location D:\Pre-Staged\DriverPacks\DriverPackNames.lst

Now we need to retrieve all the Driver Packs (Driver Pack Names) associated with a specific ConfigMgr Task Sequence and add them to the text file we created above. We can automate this step by using the following SQL query:

–SQL Query Starts here—

SELECT tsr.packageID, tsr.referencepackageid, tsr.referencename, tsp.packageid,

FROM v_tasksequenceReferencesInfo tsr

join v_tasksequencePackage tsp On tsr.packageID = tsp.packageid

WHERE =  ‘Task Sequence Name Here’

–SQL Query Ends here—

Now that we have packages referenced by a specific ConfigMgr Task Sequence, we can copy the “tsr.referencename” column results into the DriverPackNames.lst file and save it.

The hard work is over and we can now, us the below PowerShell script to pre-stage all of the packages used by the specific ConfigMgr Task Sequence.

–PowerShell Script Starts here–


# Press ‘F5’ to run this script. Running this script will load the ConfigurationManager

# module for Windows PowerShell and will connect to the site.


# This script was auto-generated at ‘9/3/2018 8:38:32 AM’.

# Uncomment the line below if running in an environment where script signing is

# required.

#Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

# Site configuration

$SiteCode = “XYZ” # Site code

$ProviderMachineName = “” # SMS Provider machine name

# Customizations

$initParams = @{}

#$initParams.Add(“Verbose”, $true) # Uncomment this line to enable verbose logging

#$initParams.Add(“ErrorAction”, “Stop”) # Uncomment this line to stop the script on any errors

# Do not change anything below this line

# Import the ConfigurationManager.psd1 module

if((Get-Module ConfigurationManager) -eq $null) {

    Import-Module “$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1” @initParams


# Connect to the site’s drive if it is not already present

if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {

    New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams


# Set the current location to be the site code.

Set-Location “$($SiteCode):\” @initParams


    $PackageName = get-content -path “D:\Pre-Staged\DriverPacks\DriverPackNames.lst”

    $FolderToSaveTo = “D:\Pre-Staged\DriverPacks”

    $DP = “”

     FOREACH($Package in $PackageName){

        $FileName = “$FolderToSaveTo\$Package.pkgx”

        Publish-CMPrestageContent -DriverPackageName $Package -FileName $FileName -DistributionPointName $DP -ErrorAction Continue


 –PowerShell Script Ends here–

Once you have entered your ConfigMgr environment details where required, you can execute the script and it will pre-stage all the Driver Packs referenced in your ConfigMgr Task Sequence.

Next, we will repeat the above steps for Applications, Boot Images and complete “Task Sequences”, the latter being the easiest in my opinion, but taking a while longer to complete as it bundles everything into one.

203 total views, 3 views today

Posted in: ConfigMgr CB 1709, Configuration Manager 2012 R2, Configuration Manger, Current Branch 1607, Current Branch 1702, Powershell, Scripts | Tags: ,

Leave a Reply