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 <<

21 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 πŸ™‚

    Reply
    • 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) πŸ™‚

      Reply
  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!

    Reply
  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

    Reply
    • 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 πŸ™‚

      Reply
  4. I’m just trying to get into this MDM stuff. I noticed it said PnP drivers. So what do we do with the non PnP drivers?

    Reply
  5. Hi Martin,
    awesome piece of work.
    One question, though, exporting the drivers of a Fujitsu Laptop resulted in a driver folder with 16GB worth of drivers, is that to be expected?

    The laptop was installed with a Win10 iso and had the manufacturers drivers applied prior to running the script.

    Cheers,
    Mike

    Reply
    • Wow. 16GB is probably a tad over the top. I’m afraid I only have Lenovo at my disposal and this is not something I have seen before. my package sizes are around 2GB each maximum.

      Reply
  6. When you say the packages are conditionally downloaded, is that using the WMI query

    SELECT * FROM Win32_ComputerSystem WHERE model LIKE “%HP Elite x2 G4%” etc?

    What benefit are you getting from downloading the package content compared to running the DISM command against the package that contains the drivers?

    Really great post by the way

    Reply
  7. Hi Martin Bengtsson,

    Congratulations for your work, this is truly handy to driver managment in SCCM.
    I’m trying to apply the drivers during PXE task sequence (after applying Operating System) but keeps failing with DISM error.
    The log says:
    “DISM.exe: Failed to access the image folder or image’s windows folder”

    The %OSDTargetSystemDrive% points do C:\, but the log says that is not a WIM mount point.

    Any thoughts?

    Best regards,

    Reply
    • I have a similar issue, DISM throws error 87 which practically means that it can’t apply the drivers to an online image (O/S), I tried moving the nested TS for the installation of the drivers after the O/S image application and it failed again. Seems I’m missing something….. πŸ™

      Reply
  8. Hi Martin,
    This is really very good post, while I am trying to import the drivers from Lenovo L380 model, I am getting the only 260MB, but I believe it should be nearly 2GB, correct me if am wrong?

    Reply
  9. Hey man, would you mind reuploading this to your github? I used this in the past a bit and would like to take another look at it if you don’t mind!

    Reply
  10. Hi Martin,

    I realise that this blog is quite old but I desperately needed a script like you shared here, however, the link is inaccessible, is there any chance for you to share it again?

    Thank you

    Reply

Leave a Comment

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