PowerShell: Modify Source Location for SCCM Drivers

I recently ran into an issue where eh hmm.. someone (not sure who but his initials are WB) imported a new set of drivers from a UNC path that was named incorrectly.  😐

To be exact, the directory was named “\\DFS\NameSpace\Share$\OSD\Win7\x64\DriverSrc\Lenovo S32_x64_R01” when in reality it was supposed to be “\\DFS\NameSpace\Share$\OSD\Win7\x64\DriverSrc\Lenovo E32_x64_R01″.

There are quite a few drivers that were imported for this particular model and there is no way in the console to bulk change the source path so after renaming the source folder to E32, off to PowerShell I went.

As you might guess I opened the PowerShell (x86) Console from the SCCM Admin Console (Still on Sp1 CU3 so no x64 PowerShell for me yet).

First I need to retrieve the driver objects that have the invalid path:
$Drivers = Get-CMDriver | Where-Object ($_.ContentSourcePath -like “*S32_x64*”}

This process takes a while as I have a lot of drivers.  If your really bored you can watch the SMSProv.log instead of stare at the PowerShell console waiting for the command to end.

Once the command completes I  have a new variable ($Drivers ) filled with all the driver objects I need to target to fix this mishap created by whoever that attention deficit admin was.  (*cough*).  For sanity sake I echo the contents out to the screen to validate I have only what I need in the variable:

$Drivers | Select-Object ContentSourcePath

I now know I have all the desired drivers that I need to modify.  My goal is to simply replace S32 with E32 in the existing path.  The command I used:

foreach ($driver in $xBackupDrivers) {$oldPath = $driver.ContentSourcePath; Write-Host “OLDPATH: $oldPath”; $NewPath = $driver.ContentSourcePath -replace “S32″,”E32”; Write-Host “NEWPATH: $NewPath”; Set-CMDriver -Id $driver.CI_ID -DriverSource $NewPath}

An easier way to read this:

foreach ($driver in $xBackupDrivers) {
    $oldPath = $driver.ContentSourcePath
    Write-Host “OLDPATH: $oldPath”
    $NewPath = $driver.ContentSourcePath -replace “S32″,”E32”
    Write-Host “NEWPATH: $NewPath”
    Set-CMDriver -Id $driver.CI_ID -DriverSource $NewPath
}

I have highlighted the commands that are doing the actual work.  I simply replace the text into a new variable and pass that to the “Set-CMDriver” cmdlet (Along with the driver CI_ID).

About 30 seconds later the drivers have the correct source path.  I’m now off to reprimand that SCCM Admin!

 

Advertisements

One thought on “PowerShell: Modify Source Location for SCCM Drivers

  1. This is great, thanks! I used this to replace a UNC path that had changed for my driver source location. The only thing I had to change was the $NewPath. If you are using a UNC path in the replace section it reads the “\” as a regex formula and doesn’t work properly. To fix this I did the following:
    $NewPath = $driver.ContentSourcePath -replace [Regex]::Escape(“\\server\share\oldfolder\”),”\\server\share\newfolder\”
    You don’t need to do a [Regex]::Escape on the second part of the replace because it reads it as plain text.

Leave a Reply

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