Update LexmarkPrinterInstall.ps1

This commit is contained in:
2026-07-15 13:10:50 +01:00
parent 13b2bca4a1
commit b4efd1ff0e
+10 -4
View File
@@ -25,7 +25,7 @@ if ($ExactDriver) {
$DriverName = $AnyLexmark.Name
Write-Host "Exact match not found. Using installed fallback: '$DriverName'" -ForegroundColor Yellow
} else {
# 3. No driver found; attempt to stage from INF
# 3. No driver found; prepare to stage from INF
Write-Host "No Lexmark drivers found installed. Attempting to stage from INF..." -ForegroundColor Yellow
if (-not (Test-Path -Path $FallbackInfPath)) {
Write-Error "CRITICAL ERROR: No Lexmark driver is installed, and the staging file '$FallbackInfPath' was not found."
@@ -48,11 +48,17 @@ $PortName = "IP_$IPAddress"
Write-Host "Starting installation for '$PrinterName'..." -ForegroundColor Cyan
# Register driver only if we detected it was missing and the INF exists
# Register driver if missing
if ($NeedsRegistration) {
Write-Host "Registering driver from INF: $DriverName..." -ForegroundColor Yellow
Write-Host "Staging driver package into Windows Driver Store..." -ForegroundColor Yellow
try {
Add-PrinterDriver -Name $DriverName -InfPath $FallbackInfPath -ErrorAction Stop
# Use pnputil to stage the driver package. This is required for Windows to trust the INF.
$pnpOutput = pnputil.exe /add-driver $FallbackInfPath /install 2>&1
Write-Host "PnPUtil: $pnpOutput" -ForegroundColor Gray
Write-Host "Registering driver in print subsystem: $DriverName..." -ForegroundColor Yellow
# Registering using only the name now that the package is trusted in the store
Add-PrinterDriver -Name $DriverName -ErrorAction Stop
Write-Host "Driver successfully registered." -ForegroundColor Green
} catch {
Write-Error "Failed to register driver: $_"