Use the Export-WindowsDriver command.
# Run with administrator privileges PowerShell
Export-WindowsDriver -Online -Destination C:\win_drivers
The Online
option indicates to target logged-in Windows.
I have not tried it, but it seems to be possible to target non-logged-in Windows by specifying a Windows folder in the Path
option.
What follows is a sample script that exports the driver and archives it as a zip file.
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string[]]
$ExportArchiveDir
)
$Timestamp = $(Get-Date -f yyyyMMddHHmmss)
$WorkDir = "$ENV:Temp\export_drivers_$Timestamp"
$ExportDir = "$WorkDir\drivers"
$LogFile = "$WorkDir\console.log"
$ExportArchive = "$ExportArchiveDir\export_drivers_$Timestamp.zip"
New-Item -ItemType "directory" -Path "$WorkDir" > $null
Export-WindowsDriver -Online -Destination "$ExportDir" >> "$LogFile"
Compress-Archive -Path "$ExportDir","$LogFile" -DestinationPath "$ExportArchive"
Remove-Item -Path "$WorkDir" -Recurse
echo "Export succeeded. $(Resolve-Path $ExportArchive)"
To write this to backup.ps1
and output an archive file in the current directory, do the following Run this in admin powershell.
> .\backup.ps1 .\
Export succeeded. C:\Users\fuji44\export_drivers_20230509201710.zip