Update samy.ps1
This commit is contained in:
56
samy.ps1
56
samy.ps1
@@ -2259,11 +2259,11 @@ 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
|
# 4a) Stage the driver package with pnputil
|
||||||
$pnputilCmd = "pnputil.exe /add-driver `"$infPath`" /install"
|
$pnputilCmd = "pnputil.exe /add-driver `"$infPath`" /install"
|
||||||
Write-LogHybrid "Running: $pnputilCmd" Info Printers -LogToEvent
|
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
|
$exitCode = $LASTEXITCODE
|
||||||
|
|
||||||
Write-LogHybrid "pnputil exit code: $exitCode. Output:`n$pnputilOutput" Info Printers -LogToEvent
|
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'."
|
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,
|
# 4b) Register the printer driver with Add-PrinterDriver
|
||||||
# but DO NOT hard-fail if we can't find it by exact name.
|
try {
|
||||||
$existingDriver = Get-PrinterDriver -ErrorAction SilentlyContinue | Where-Object {
|
Write-LogHybrid "Calling Add-PrinterDriver -Name '$driverName' -InfPath '$infPath'." Info Printers -LogToEvent
|
||||||
$_.Name -eq $driverName -or
|
Add-PrinterDriver -Name $driverName -InfPath $infPath -ErrorAction Stop
|
||||||
$_.Name -like "*$driverName*" -or
|
}
|
||||||
$driverName -like "*$($_.Name)*"
|
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) {
|
# 4c) Final verification
|
||||||
$sharpDrivers = Get-PrinterDriver -ErrorAction SilentlyContinue |
|
Start-Sleep -Seconds 2
|
||||||
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."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify driver presence (by name)
|
|
||||||
$existingDriver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
$existingDriver = Get-PrinterDriver -Name $driverName -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if (-not $existingDriver) {
|
if (-not $existingDriver) {
|
||||||
# Optional: log what SHARP drivers *do* exist to catch name mismatches
|
$sharpNames = (Get-PrinterDriver -ErrorAction SilentlyContinue |
|
||||||
$sharpNames = (Get-PrinterDriver | Where-Object Name -like '*SHARP*' |
|
Where-Object Name -like 'SHARP*' |
|
||||||
Select-Object -ExpandProperty Name) -join ', '
|
Select-Object -ExpandProperty Name) -join ', '
|
||||||
|
|
||||||
Write-LogHybrid "After pnputil, driver '$driverName' not found. Existing SHARP drivers: $sharpNames" Warning Printers -LogToEvent
|
if (-not $sharpNames) { $sharpNames = '(none)' }
|
||||||
throw "Failed to find printer driver '$driverName' after pnputil install."
|
|
||||||
|
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 {
|
function Install-SamyTcpIpPrinter {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
|
|||||||
Reference in New Issue
Block a user