Update LexmarkPrinterInstall.ps1

This commit is contained in:
2026-06-15 17:12:44 +01:00
parent dad6c83863
commit fa2921025d
-16
View File
@@ -3,12 +3,8 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
Write-Warning "Please run this script as an Administrator!"
Exit
}
# Define driver variables at the top for verification
$DriverName = "Lexmark Universal v2 XL"
$InfPath = "C:\Windows\INF\oem59.inf"
# 1. Pre-check: Terminate if the driver INF is missing from the device
Write-Host "Verifying driver availability..." -ForegroundColor Cyan
if (-not (Test-Path -Path $InfPath)) {
Write-Error "CRITICAL ERROR: The required driver file '$InfPath' was not found on this device."
@@ -17,30 +13,20 @@ if (-not (Test-Path -Path $InfPath)) {
} else {
Write-Host "Driver INF found at $InfPath." -ForegroundColor Green
}
# 2. Prompt the user for the IP Address and Printer Name
Write-Host ""
$IPAddress = Read-Host -Prompt "Enter the printer's IP address (e.g., 10.59.121.22)"
$PrinterName = Read-Host -Prompt "Enter the custom name for this printer (e.g., Skoda Sales)"
# Clean up any accidental leading/trailing spaces
$IPAddress = $IPAddress.Trim()
$PrinterName = $PrinterName.Trim()
$PortName = "IP_$IPAddress"
Write-Host "`nStarting installation for '$PrinterName'..." -ForegroundColor Cyan
# 3. Register the Printer Driver into the Spooler
Write-Host "Registering driver: $DriverName..." -ForegroundColor Yellow
try {
Add-PrinterDriver -Name $DriverName -InfPath $InfPath -ErrorAction Stop
Write-Host "Driver successfully verified/registered." -ForegroundColor Green
} catch {
# If it's already registered, Add-PrinterDriver might throw a non-critical exception
Write-Host "Note: Driver registration status: $_" -ForegroundColor DarkYellow
}
# 4. Create the Printer Port (Checks if it exists first to avoid duplicates)
Write-Host "Creating printer port: $PortName..." -ForegroundColor Yellow
if (Get-PrinterPort -Name $PortName -ErrorAction SilentlyContinue) {
Write-Host "Port $PortName already exists. Skipping port creation." -ForegroundColor Green
@@ -53,8 +39,6 @@ if (Get-PrinterPort -Name $PortName -ErrorAction SilentlyContinue) {
Exit
}
}
# 5. Install the Printer
Write-Host "Installing printer asset..." -ForegroundColor Yellow
try {
Add-Printer -DriverName $DriverName -Name $PrinterName -PortName $PortName -ErrorAction Stop