Skip to content

Instantly share code, notes, and snippets.

@fuji44
Last active January 15, 2024 12:17
Show Gist options
  • Save fuji44/9ded9c7567219e094a02a7b18bf6a275 to your computer and use it in GitHub Desktop.
Save fuji44/9ded9c7567219e094a02a7b18bf6a275 to your computer and use it in GitHub Desktop.
Backup of drivers without third-party tools in Windows

Backup of drivers without third-party tools in Windows

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment