Almost Modern Driver Management with ConfigMgr and Powershell

Introduction

First off, bear with me here during the intro. I know introductions usually are boring, but I do have a few words to share with you first.

The following is by no means any substitution for any other Modern Driver Management solution out there. This is purely me exploring, learning and sharing that experience with anyone who’s interested. When I find something useful, I usually try to do my own thing for various reasons, but mainly to learn and also for being less dependent on others work and future maintenance plans.

Now, this post is primarily about a Powershell script and how that Powershell script is designed to run on a given device and export the device drivers into your ConfigMgr source file library or locally. In the process, the script is able to create a regular package in ConfigMgrΒ containing those drivers. The post is also about how to use the regular packages for applying drivers, but the script is what took the most of my time πŸ™‚

The idea here is, that you fire up a given device with a given version of Windows (preferably Windows 10) and install ALL the drivers (preferably the latest drivers) and verify that everything works in that combination ofΒ  Windows, drivers and hardware model.

Note: Most vendors provide a tool which checks online for latest drivers and gives you option to install those. This is pretty handy when building new drivers for a given computer model.

Now knowing that everything works, this is the drivers you want to apply to future deployments of this computer model, so you run the script and everything is automatically exported and a package in ConfigMgr is created.

In lack of a better name, this is what I call ‘Almost Modern Driver Management‘. πŸ˜€

PS. If you’re looking for a truly nifty and ‘modern’ approach, I suggest you head over to SCConfigMgr.com and take a peek at their solutions for both BIOS and drivers.

Almost what?

I recently did this to my ConfigMgr environment. It felt really good. Not because the regular way of doing drivers doesn’t work, it just quite easily becomes an administrative mess.

Instead I’m now doing this, keeping the drivers in regular packages. The packages shown here are the ones created with the Powershell script (Again, inspiration and help from @modaly_it)

And the content of the packages created will look similar to below (Note: It’s on my to-do to rename the native provided folders into a more friendly name. For now this will do just fine)

Using The Packages

I’m using the regular packages in a separate Task Sequence. Each package are conditionally downloaded with the Download Package Content step, and stored into the custom path: %_SMSTSMDataPath%\Drivers

And the drivers are applied ‘manually’ through DISM with a Run Command Line step:

DISM.exe /Image:%OSDTargetSystemDrive%\ /Add-Driver /Driver:%_SMSTSMDataPath%\Drivers /Recurse /logpath:%_SMSTSLogPath%\dism.log

The ‘Apply Drivers‘ step is only run if drivers actually are downloaded. As of such, add a condition to the step similar to below

And on the ‘Apply Drivers Using DISM‘ step, add success code ’50’ to the list. (DISM returns 50 when applying a driver)

And finally, the nested Task Sequence is used with the relevant main Task Sequences deploying the relevant version of Windows 10.

If you have several task sequences deploying the same OS version, this is preferred as you only have to modify the nested task sequence in order to affect everything.

The Powershell Script

There are 3 places in the script where you will have to make edits. Those are all marked with the comment ### EDIT HERE ###

Those places are:

  • # SCCM specific variables
  • # Directories where drivers are exported to
  • # Get all Plug and Play devices on the computer

The script log all actions to ProgramData\Export-InstalledDrivers\Export-InstalledDrivers.log

If the script is run with the -ImportSCCM parameter, the user that runs the script is required to have permissions to create packages in the specified Configuration Manager environment.

The script also requires access to the Configuration Manager Powershell module in the default path: $ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1 which is installed with the console.

The script does following in headlines:

  • Gets all Plug and Play devices from WMI
  • Gets all Plug and Play drivers in WMI that matches the devices found
  • Finds the matching driver in the driver store file repository: C:\Windows\System32\DriverStore\FileRepository
  • Adds the full path to the driver into an array
  • Copies all the drivers found out to the SCCM source file library (if run with -ImportSCCM) or down locally to C:\Temp\Drivers (if not run with -ImportSCCM)
  • Create folder in SCCM if it doesn’t exist
  • Create package in SCCM with the drivers
  • Move the package in SCCM into the folder

The script has been tested on following Lenovo models:

  • X1 Yoga 2nd
  • X1 Yoga 3rd
  • X240
  • X250
  • X260
  • X270
  • X280
  • T440S
  • T450S
  • T460S
  • T470S
  • T480S

Download Script

>> https://gallery.technet.microsoft.com/Export-current-drivers-and-084b21cf <<

9 thoughts on “Almost Modern Driver Management with ConfigMgr and Powershell”

  1. Thank You for this great guide. Been trying to do a nested task Sequences driver deployment but my powershell skills an how the layout of such a task sequense should be was beyond my skill level πŸ™‚

    • Hey Adam, yeah, I came across your post when searching the web for knowledge. Great work – and thanks for sharing yet again πŸ™‚ ( btw: your code snippet plugin is evil and when copy/pasting your script you get all sorts of nonsense with it) πŸ™‚

  2. Hi,
    Nice script! Was wondering as to where this nested task sequence\ driver step would fit into an SCCM MDT integrated task sequence?
    Cheers!

  3. Hi,
    Thank for your work and great posts. Just had a quick question. When using an Baremetal SCCM \MDT integrated task sequence, where would the best placement in the task sequence be for this step?
    thank you again

    • Hey Dylan, make sure to edit the line that only selects the first PnP device. Line 197 and 198. I only select the first 1 for testing. You need to swap around the commenting πŸ™‚

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.