Install Universal Print Driver and Map Printer

This script will first check if 7zip is installed and if not then install it. Then the script downloads HP Universal PS Driver, installs the driver and then maps a specific printer by IP.

# Check if 7-Zip is installed
if (!(Test-Path "C:\Program Files\7-Zip\7z.exe")) {
    Write-Host "7-Zip not found. Downloading and installing..."

    # URL to the 7-Zip installer (MSI) for 64-bit
    $sevenZipUrl = "https://7-zip.org/a/7z2301-x64.msi"
    $sevenZipPath = "C:\Temp\7z2301-x64.msi"

    # Ensure the directory exists
    if (!(Test-Path -Path "C:\Temp")) {
        New-Item -ItemType Directory -Path "C:\Temp" | Out-Null
    }

    # Download 7-Zip
    Invoke-WebRequest -Uri $sevenZipUrl -OutFile $sevenZipPath

    # Install 7-Zip
    Start-Process -FilePath "msiexec.exe" -ArgumentList "/i", $sevenZipPath, "/q", 'INSTALLDIR="C:\Program Files\7-Zip"' -Wait

    # Check if the installation was successful
    if (Test-Path "C:\Program Files\7-Zip\7z.exe") {
        Write-Host "7-Zip installed successfully."
    }
    else {
        Write-Host "7-Zip installation failed."
        exit 1
    }
}
# Download the file
$url = "https://ftp.hp.com/pub/softlib/software13/printers/UPD/upd-ps-x64-7.1.0.25570.exe"
$outputPath = "C:\Temp\upd-ps-x64-7.1.0.25570.exe"

# Ensure the directory exists
if (!(Test-Path -Path "C:\Temp")) {
    New-Item -ItemType Directory -Path "C:\Temp" | Out-Null
}

# Download the file
Invoke-WebRequest -Uri $url -OutFile $outputPath

# Extract the .exe file
& 'C:\Program Files\7-Zip\7z.exe' x $outputPath -oC:\HPUniversalPrintDriver

# Add the driver to the system. Change to specific driver required.
pnputil /add-driver "C:\HPUniversalPrintDriver\*.inf" /install

# Add the printer driver to the system. Change to Driver Name if others are needed.
Add-PrinterDriver -Name "HP Universal Printing PS (v7.1.0)"

# Define the printer properties
$printerIP = "192.168.1.1"
$printerPortName = "IP_" + $printerIP
$printerName = "MY-HP-Printer-Name"
$driverName = "HP Universal Printing PS (v7.1.0)" # Specify the exact driver name for your system

# Create a new TCP/IP port for the printer
Add-PrinterPort -Name $printerPortName -PrinterHostAddress $printerIP

# Check if a printer with the same name already exists, if so remove it
if (Get-Printer | Where-Object Name -eq $printerName) {
    Remove-Printer -Name $printerName
}

# Add the printer
Add-Printer -Name $printerName -DriverName $driverName -PortName $printerPortName

# Output success message
Write-Host "Printer $printerName has been installed successfully on port $printerPortName with driver $driverName"
Share or Save this:
Share