Files
LexmarkPrinter/LexmarkPrinterInstall.ps1
T

47 lines
2.2 KiB
PowerShell

if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Warning "Please run this script as an Administrator!"
Exit
}
$DriverName = "Lexmark Universal v2 XL"
$InfPath = "C:\Windows\INF\oem59.inf"
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."
Write-Host "Installation aborted. Please stage the driver package before running this script." -ForegroundColor Red
Exit
} else {
Write-Host "Driver INF found at $InfPath." -ForegroundColor Green
}
Write-Host ""
$IPAddress = Read-Host -Prompt "Enter the printer's IP address (e.g., 192.168.1.50)"
$PrinterName = Read-Host -Prompt "Enter the custom name for this printer (e.g., Service printer)"
$IPAddress = $IPAddress.Trim()
$PrinterName = $PrinterName.Trim()
$PortName = "IP_$IPAddress"
Write-Host "`nStarting installation for '$PrinterName'..." -ForegroundColor Cyan
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 {
Write-Host "Note: Driver registration status: $_" -ForegroundColor DarkYellow
}
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
} else {
try {
Add-PrinterPort -Name $PortName -PrinterHostAddress $IPAddress -ErrorAction Stop
Write-Host "Port successfully created." -ForegroundColor Green
} catch {
Write-Error "Failed to create printer port: $_"
Exit
}
}
Write-Host "Installing printer asset..." -ForegroundColor Yellow
try {
Add-Printer -DriverName $DriverName -Name $PrinterName -PortName $PortName -ErrorAction Stop
Write-Host "Successfully installed '$PrinterName' on port $PortName!" -ForegroundColor Green
} catch {
Write-Error "Failed to install the printer: $_"
}