Update samy.ps1

This commit is contained in:
2025-12-05 20:05:48 -05:00
parent 6827f93905
commit 37b4aac268

View File

@@ -2259,14 +2259,45 @@ function Ensure-SamyPrinterDriver {
Write-LogHybrid "Installing printer driver '$driverName' from '$infPath'." Info Printers -LogToEvent
Write-LogHybrid "Installing printer driver '$driverName' from '$infPath'." Info Printers -LogToEvent
# Run pnputil and capture output + exit code
$pnputilCmd = "pnputil.exe /add-driver `"$infPath`" /install"
Write-LogHybrid "Running: $pnputilCmd" Info Printers -LogToEvent
$pnputilOutput = & pnputil.exe /add-driver "`"$infPath`"" /install 2>&1
$exitCode = $LASTEXITCODE
Write-LogHybrid "pnputil exit code: $exitCode. Output:`n$pnputilOutput" Info Printers -LogToEvent
if ($exitCode -ne 0) {
throw "pnputil failed with exit code $exitCode installing '$driverName' from '$infPath'."
}
# Best-effort verification: try to see if a matching SHARP driver is visible now,
# but DO NOT hard-fail if we can't find it by exact name.
$existingDriver = Get-PrinterDriver -ErrorAction SilentlyContinue | Where-Object {
$_.Name -eq $driverName -or
$_.Name -like "*$driverName*" -or
$driverName -like "*$($_.Name)*"
}
if (-not $existingDriver) {
$sharpDrivers = Get-PrinterDriver -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like "SHARP*" }
$sharpList = if ($sharpDrivers) {
($sharpDrivers | Select-Object -ExpandProperty Name) -join ', '
} else {
'(none)'
}
Write-LogHybrid "After pnputil, driver '$driverName' not found. Existing SHARP drivers: $sharpList" Warning Printers -LogToEvent
# NOTE: we intentionally do NOT throw here anymore.
}
else {
Write-LogHybrid "Printer driver '$($existingDriver.Name)' is present after pnputil (requested '$driverName')." Success Printers -LogToEvent
}
if ($exitCode -ne 0) {
throw "pnputil failed with exit code $exitCode. See Printers logs for details."
}