From b4efd1ff0ebc5fab32808f37d38c26b71db4d9b0 Mon Sep 17 00:00:00 2001 From: CristianD Date: Wed, 15 Jul 2026 13:10:50 +0100 Subject: [PATCH] Update LexmarkPrinterInstall.ps1 --- LexmarkPrinterInstall.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/LexmarkPrinterInstall.ps1 b/LexmarkPrinterInstall.ps1 index e66fc85..68f10c1 100644 --- a/LexmarkPrinterInstall.ps1 +++ b/LexmarkPrinterInstall.ps1 @@ -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: $_"