Overview
This is a procedure for bulk exporting installed drivers from Windows that can be used when you want to backup drivers during Windows 11 migration or when creating your own PC, or when you want to archive acquired versions of driver packs for troubleshooting. This is a command-based script that saves the text of the export log and the list of installed drivers as text.
Script Design
There are a few quirks in the description due to the creation and lengthening of the branch. I designed the following
Explanation and Purpose
Target Audience
Export Command
Save the following as a BAT file.
The description of echo is written in English, so it may be easier to use if you can translate it into Japanese if necessary. If you do so, please set the strings to ANSI to avoid character corruption. Some delayed environment variables are used for convenience of the command.
@echo off
setlocal enabledelayedexpansion
echo ---------------------------------------
echo Start Driver Export
echo Running. Please keep waiting...
echo ---------------------------------------
set "model="
for /f "skip=1 delims=" %%a in ('wmic computersystem get model') do if not defined model set "model=%%a"
set "model=%model: =%"
set "model=%model:_=%"
if exist "C:\Drivers\%model%" (
echo The directory C:\Drivers\%model% already exists.
echo.
set /p overwrite="Do you want to overwrite it? (Y/N):"
if /i "!overwrite!"=="y" goto :yes
if /i "!overwrite!"=="Y" goto :yes
if /i "!overwrite!"=="n" goto :no
if /i "!overwrite!"=="N" goto :no
echo Invalid input. Please enter Y or N.
pause
EXIT
)
REM ------------ Yes Overwrite --------------
:yes
echo Yes. Export new File. Prease waiting...
md "C:\Drivers\%model%"
dism /online /export-driver /destination:"C:\Drivers\%model%" > "C:\Drivers\%model%\DriverExport_log.txt"
echo ---------------------------------------
echo Record the list of drivers installed on the PC to text using pnputil.
echo.
echo This is the reference source if you want to know the details of the OEM file name recorded in DriverExport_log.txt
echo ---------------------------------------
pnputil /enum-drivers > "C:\Drivers\%model%\DriverList.txt"
if not errorlevel 0 (
echo "Errors occurred"
pause
) else (
echo "Driver export is completed"
pause
)
REM --------------- No stop -----------------
:no
echo Processing stopped because N was selected
pause
EXIT
endlocal
Install Command
As a supplement, we also write a few installation commands to make use of the exported drivers.
There are two main installation methods: Windows online and offline, with different commands depending on whether Windows is online or offline. Offline means that you are not running Windows, but have mounted Windows, such as by mounting Wim or by running WindowsPE.
This time, the offline state is assumed to be during Windows OS deployment image creation.
Windows online case
In the following command example, the drivers are placed in C:\drivers. The PATH should be changed according to your environment.
Microsoft Official PnPUtil Examples
Since Windows is online, some drivers may fail to overwrite. In this case, consider booting the PC from Windows PE, etc. and installing offline.
pnputil /add-driver C:\drivers\*inf /subdirs /install
Windows offline case
In the following command example, the drivers are placed in N:\drivers. The PATH can be changed to suit your environment. The drive letter can be set appropriately.
Microsoft Official Add and Remove Driver packages to an offline Windows Image
DISM /image:C:\ add-driver /Driver:N:\drivers /Recurse