Skip to content

Instantly share code, notes, and snippets.

@realchrisolin
Last active November 13, 2025 16:59
Show Gist options
  • Select an option

  • Save realchrisolin/587475c835e35854146708be1112bcd7 to your computer and use it in GitHub Desktop.

Select an option

Save realchrisolin/587475c835e35854146708be1112bcd7 to your computer and use it in GitHub Desktop.
Powershell script to install HP Universal Printer Driver silently / unattended
* Background *
Public resources for installing HP Universal Printer Drivers are outdated or otherwise misleading (e.g. https://h30434.www3.hp.com/t5/Printer-Setup-Software-Drivers/How-to-silent-install-for-HP-Universal-driver/td-p/9289037)
It also seems that as of April 2025, HP is no longer distributing the self-extracting archive and instead offers a generic .zip file with the interactive installer bundled inside.
The powershell script in this gist is a modified version of a script I wrote to deploy the HP UPD in a Windows Provisioning Package. The modifications are to try idiotproofing the script and make it more compatible with public consumption.
* Prerequisites *
- Download the PCL6 HP Universal Printer Driver from https://support.hp.com/ca-en/drivers/hp-universal-print-driver-series-for-windows/4157320
* if you download the PostScript version, the script will fail
- If you download the self-extracting .exe package, rename the file extension to .zip
- Place InstallHPUniversalPrinterDriver.ps1 in the same directory as the zip bundle.
- Open an admin cmd prompt, cd to path\to\driver.zip and run the script with `powershell.exe -ExecutionPolicy Bypass -File InstallHPUniversalPrinterDriver.ps1`
# Setup temp directory
$prep_dir = "C:\Windows\Temp"
if (-not (Test-Path $prep_dir)) {
New-Item -Path $prep_dir -ItemType Directory -Force | Out-Null
}
Start-Transcript -Path "$($prep_dir)\InstallHPUniversalPrinterDriver.log"
# Find the latest UPD archive file based on version
$updArchives = Get-ChildItem -Path . -Filter "upd-pcl6-x64-*.zip"
if ($updArchives.Count -eq 0) {
Write-Host "ERROR: No UPD archive files found matching pattern 'upd-pcl6-x64-*.zip'" -ForegroundColor Red
Stop-Transcript
exit 1
} elseif ($updArchives.Count -gt 1) {
Write-Host "WARNING: Multiple UPD archive files found. Selecting the most recent version." -ForegroundColor Yellow
# Extract version numbers and sort to find latest
$latestArchive = $updArchives |
ForEach-Object {
# Extract version number from filename (assumes format like upd-pcl6-x64-7.2.0.25780.zip)
if ($_.Name -match 'upd-pcl6-x64-(\d+\.\d+\.\d+\.\d+)\.zip') {
$version = $matches[1]
[PSCustomObject]@{
File = $_
Version = [Version]$version
}
} else {
[PSCustomObject]@{
File = $_
Version = [Version]"0.0.0.0" # Default for files without version
}
}
} | Sort-Object -Property Version -Descending | Select-Object -First 1
$archiveFile = $latestArchive.File
Write-Host "Selected archive: $($archiveFile.Name)" -ForegroundColor Cyan
} else {
$archiveFile = $updArchives[0]
Write-Host "Found archive: $($archiveFile.Name)" -ForegroundColor Cyan
}
# Extract the archive
Expand-Archive -Path $archiveFile.FullName -DestinationPath "$prep_dir\HP_UPD" -Force
# Find the driver INF file that begins with "hpcu"
$driverInfFiles = Get-ChildItem -Path "$prep_dir\HP_UPD" -Filter "hpcu*.inf"
if ($driverInfFiles.Count -eq 0) {
Write-Host "ERROR: No driver INF files found matching pattern 'hpcu*.inf'" -ForegroundColor Red
Stop-Transcript
exit 1
} elseif ($driverInfFiles.Count -gt 1) {
Write-Host "Multiple driver INF files found. Using first match." -ForegroundColor Yellow
}
$driverInfFile = $driverInfFiles[0]
$driverBaseName = [System.IO.Path]::GetFileNameWithoutExtension($driverInfFile.Name)
Write-Host "Using driver file: $($driverInfFile.Name)" -ForegroundColor Cyan
# Add the driver to the driver store
Write-Host "Adding driver to driver store..." -ForegroundColor Cyan
pnputil /add-driver "$($driverInfFile.FullName)"
# Find the installed driver in FileRepository
$basePath = "C:\WINDOWS\system32\DriverStore\FileRepository"
$driverPattern = "$($driverBaseName).inf_amd64_*"
$fileName = "$($driverBaseName).inf"
Write-Host "Searching for installed driver with pattern: $driverPattern" -ForegroundColor Cyan
$driverPath = Get-ChildItem -Path $basePath -Directory -Filter $driverPattern | Select-Object -First 1
if ($driverPath) {
$fullPath = Join-Path -Path $driverPath.FullName -ChildPath $fileName
Write-Host "Found driver at: $fullPath" -ForegroundColor Green
# Add the printer driver
Write-Host "Adding printer driver 'HP Universal Printing PCL 6'..." -ForegroundColor Cyan
Add-PrinterDriver -Name "HP Universal Printing PCL 6" -InfPath $fullPath
Write-Host "Driver installation complete." -ForegroundColor Green
} else {
Write-Host "ERROR: Driver installation failed. Could not find driver in $basePath" -ForegroundColor Red
}
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment