SCCM – Updating all drivers after a migration

Every time you migrate from one SCCM instance to another, or if you have to move your drivers around (for instance: you originally had your drivers placed on the c:\ and want to mover them to another drive), you’ll need to update the location not only of DriverPackages, but also of all drivers as well.

This has been something that I MIGHT have forgotten more than once.  More than twice even.

So I wrote up this script.

This script assumes that you’ve already moved your drivers from their original location to their final resting place.  It also supports adjusting the path based on driver folder as well.  I’m a firm believer that SCCM Drivers should be stored in as small a folder structure as is possible, here’s how I normally layout my content for SCCM:

Type Of Content Location Shared Path
All SCCM Content D:\ContentSource \\SCCM\Content\
Drive Source Files D:\ContentSource\Drivers \\SCCM\Content\Drivers
Driver Packages D:\ContentSource\DriverPackages \\SCCM\Content\DriverPackages

So when I saw that this instance of SCCM had the content in the C:\ drive, and also had very long path names, I had to truncate things.  That’s why in this script, you’ll see separate logic for HP, Dell and Sony Drivers, as we needed to shorten those paths a bit.

Original Path New Path
Drivers\HP Drivers Drivers\HP
Drivers\Dell Drivers Drivers\Dell
Drivers\Sony Drivers Drivers\Sony

Assuming you’re moving your drivers from one system, to another, simply update the path on lines 8, 16 & 24.  If you don’t need to change folders, like I’m doing, then you can delete the three blocks and only use one.

Finally, this will take a LONG, LONG time.  We had ~3,000 drivers and it took about three hours or so.

Output looks like this:

IMG_3827

Set-CMQueryResultMaximum -Maximum 5000

$drivers = get-cmdriver

foreach ($driver in ($drivers)) {

     If ($driver.ContentSourcePath -like "*PackageSource*hp drivers*"){
               $newPath = $driver.ContentSourcePath -replace 'PackageSource\\Drivers\\HP Drivers','DriverPackages\HP'
               Write-host -ForegroundColor Cyan "Changing PkgSourcePath for $($driver.Name)..."
               $newPath
               Set-CMDriver -Id $driver.CI_ID -DriverSource $NewPath
               timeout 5
           }

            If ($driver.ContentSourcePath -like "*PackageSource*dell*"){
                $newPath = $driver.ContentSourcePath -replace 'PackageSource\\Drivers\\Dell Drivers','DriverPackages\Dell'
                Write-host -ForegroundColor Cyan "Changing PkgSourcePath for $($driver.Name)..."
                $newPath
                Set-CMDriver -Id $driver.CI_ID -DriverSource $NewPath
                timeout 5
           }

           if ($driver.ContentSourcePath -like "*PackageSource*sony*"){
                $newPath = $driver.ContentSourcePath -replace 'PackageSource\\Drivers\\Sony Drivers','DriverPackages\Sony'
                Write-host -ForegroundColor Cyan "Changing PkgSourcePath for $($driver.Name)..."
                $newPath
                Set-CMDriver -Id $driver.CI_ID -DriverSource $NewPath
                timeout 5
           }

}
Advertisements

One thought on “SCCM – Updating all drivers after a migration

  1. Tony January 31, 2016 / 3:12 am

    Cool!

    I need to write a similiar script to clean up my movie folder…… 😀

Have a code issue? Share your code by going to Gist.github.com and pasting your code there, then post the link here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s