Manage Learn to apply best practices and optimize your operations.

Add Custom Drivers to WinRE

The Windows Recovery Environment (aka Windows or RE or WinRE) is a valuable tool for system recovery. But on some PCs, the standard collection of device drivers packaged with Windows itself may not cover your needs. You’ll know if this means you when you find you must add device drivers after completing a clean Windows install or an upgrade install. That’s when it make sense to add custom drivers to WinRE as well. If your regular runtime needs them, your recovery runtime will probably need them also. This turns out to be a simple task.

By default, WinRE.wim resides inside the Windows Recovery partition. Shown using Partition Explorer in MiniTool Partition Wizard.
[Click image for full-sized view]

How to Add Custom Drivers to WinRE

The secret lies to using the Deployment Image Servicing and Management, or DISM, command built into modern Windows versions. That means Windows 7 and newer on the desktop, Windows Server 2008 and newer on the server side of things. Windows 10 users can run some specific PowerShell cmdlets instead to get the job done. Because this involves working on an image file, the basic process works like this:

  1. Mount the Windows image (.wim) file you wish to operate upon
  2. Add the device drivers needed to that image
  3. Dismount the mounted Windows image so it may then be used

For more information on this, please consult the MS Hardware Dev Center document “WinPE: Mount and Customize.” It’s very helpful.

A Script to Add Custom Drivers to WinRE

The operation of the PowerShell script provided here depends on a crafty trick to simplify adding drivers. That trick involves copying all the necessary driver files into a single directory, from which DISM will then add them to the mounted image. For the purposes of this script, I put them into a directory named C:\temp\Drivers. You can put them wherever you want, but that’s where you’ll have to reference them in the command script in place of that reference.

The script also references the version of WinRE that’s included with Macrium Reflect Free, a free and capable backup and restore program. Reflect includes a nice recovery environment, boot repair tools, and more. If you’d rather use a plain-vanilla WinRE image instead, you can. You may find the file named WinRE.wim in C:\Windows\Recovery. Otherwise, if you have access to a recovery partition on one of your disks, you’ll find it at: <DL>:\Recovery\WindowsRE. Of course, <DL> stands for Drive Letter, which means you’ll need to assign a drive letter to the recovery partition (at least temporarily), then use that letter to see (and grab) the WinRE.wim file.

Here’s the script:

# Mount WIM (remove linefeeds following comments # here)
# Each of the mount, add, and unmount commands go on one line
Mount-WindowsImage -ImagePath 
"C:\boot\macrium\WA10KFiles\media\sources\boot.wim" 
-index 1 -Path "C:\temp\mount"

# Add any device drivers (.inf files)
Add-WindowsDriver -Path "C:\temp\mount" 
-Driver "C:\temp\Drivers\" -recurse

# Unmount the WinPE image
Get-WindowsImage -Mounted -ErrorAction Stop 
| ForEach-Object { Dismount-WindowsImage -Path 
$_.Path -Save -ErrorAction Stop }

Capturing Drivers for Use with WinRE Customization

The every-handy DISM command also captures drivers, too. Once you get your current Windows installation set up the way you want it, with all drivers up-to-date, it will take a snapshot for you. You can use DISM to populate the afore-cited C:\temp\Drivers directory by entering:

dism /online /export-driver /destination:C:\temp\Drivers

at an administrative command prompt, or in PowerShell (admin). Then, you can run the foregoing script, secure in the knowledge that all the drivers you need will be added therein.

[Note: my thanks to user Lx07 at TenForums.com, who posted the original of this script in the message thread entitled “How do I make Wifi work in PE?” on 10/9/2015. I’ll observe that the directory spec for the Macrium boot.wim has changed since then, too. My pointer as referenced in the preceding script is correct for versions 9 and 10. For the record, for a Windows Recovery partition on drive L:, the file specification would be L:\Recovery\WindowsRE\WinRE.wim.]