Update samy.ps1

This commit is contained in:
2025-12-06 00:39:09 -05:00
parent 37b4aac268
commit 8d73b6aaa2

View File

@@ -2257,13 +2257,13 @@ function Ensure-SamyPrinterDriver {
throw "Driver '$driverName' is not installed and no valid DriverInfPath or usable driver package is available for profile '$($Profile.ProfileName)'."
}
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
# 4a) Stage the driver package with pnputil
$pnputilCmd = "pnputil.exe /add-driver `"$infPath`" /install"
Write-LogHybrid "Running: $pnputilCmd" Info Printers -LogToEvent
$pnputilOutput = & pnputil.exe /add-driver "`"$infPath`"" /install 2>&1
$pnputilOutput = & pnputil.exe /add-driver "$infPath" /install 2>&1
$exitCode = $LASTEXITCODE
Write-LogHybrid "pnputil exit code: $exitCode. Output:`n$pnputilOutput" Info Printers -LogToEvent
@@ -2272,53 +2272,39 @@ function Ensure-SamyPrinterDriver {
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)*"
# 4b) Register the printer driver with Add-PrinterDriver
try {
Write-LogHybrid "Calling Add-PrinterDriver -Name '$driverName' -InfPath '$infPath'." Info Printers -LogToEvent
Add-PrinterDriver -Name $driverName -InfPath $infPath -ErrorAction Stop
}
catch {
Write-LogHybrid "Add-PrinterDriver failed for '$driverName' using '$infPath': $($_.Exception.Message)" Error Printers -LogToEvent
throw "Add-PrinterDriver failed for '$driverName': $($_.Exception.Message)"
}
if (-not $existingDriver) {
$sharpDrivers = Get-PrinterDriver -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like "SHARP*" }
# 4c) Final verification
Start-Sleep -Seconds 2
$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."
}
# Verify driver presence (by name)
$existingDriver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
if (-not $existingDriver) {
# Optional: log what SHARP drivers *do* exist to catch name mismatches
$sharpNames = (Get-PrinterDriver | Where-Object Name -like '*SHARP*' |
$sharpNames = (Get-PrinterDriver -ErrorAction SilentlyContinue |
Where-Object Name -like 'SHARP*' |
Select-Object -ExpandProperty Name) -join ', '
Write-LogHybrid "After pnputil, driver '$driverName' not found. Existing SHARP drivers: $sharpNames" Warning Printers -LogToEvent
throw "Failed to find printer driver '$driverName' after pnputil install."
if (-not $sharpNames) { $sharpNames = '(none)' }
Write-LogHybrid "After pnputil/Add-PrinterDriver, driver '$driverName' not found. Existing SHARP drivers: $sharpNames" Warning Printers -LogToEvent
throw "Failed to find printer driver '$driverName' after Add-PrinterDriver."
}
Write-LogHybrid "Printer driver '$driverName' installed successfully." Success Printers -LogToEvent
Write-LogHybrid "Printer driver '$driverName' installed and detected successfully." Success Printers -LogToEvent
}
function Install-SamyTcpIpPrinter {
[CmdletBinding()]
param(