Installing Printers with PowerShell

Whenever possible stick to a single manufacturer for printers at clients. It makes it so installing them from your RMM is as easy as a single script with a single driver.

The first step to installing a printer is to setup the driver for it. My script uses the HP Universal Driver, but you can also find a similar universal driver from other manufacturers.

$DriverName = "HP Universal Printing PCL 6"
function Install-HPDriver($DriverName) {
  if(Get-PrinterDriver | Where-Object Name -eq $DriverName) { return $true }
  $DriverUri = "https://www.dropbox.com/s/40jdl2ogkogdn9c/win10-x64-hp-universal-pcl6.zip?dl=1"
  $DownloadFile = Join-Path -Path $env:TEMP -ChildPath win10-x64-hp-universal-pcl6.zip
  $DriverTempPath = Join-Path -Path $env:TEMP -ChildPath hp-universal-pcl6

  if ($(Test-Path $DriverTempPath) -eq $false) {
      Invoke-WebRequest -Uri $DriverUri -OutFile $DownloadFile
      Expand-Archive -Path $DownloadFile -DestinationPath $DriverTempPath
  }

  # Install the driver
  $DriverPath = Join-Path -Path $DriverTempPath -ChildPath hpcu220u.inf
  $PnpUtil = Join-Path -Path $env:windir -ChildPath "System32\pnputil.exe"
  & "$PnpUtil" /add-driver $DriverPath
  Add-PrinterDriver -Name $DriverName
}

Install-HPDriver -DriverName "HP Universal Printing PCL 6"

After you've installed and registered the driver, you can setup printers by initializing the port and then assigning the printer:

function Install-Printer($Address, $Name, $DriverName) {
  if (Get-Printer | Where-Object Name -eq $Name) { return $true }
  Add-PrinterPort -Name "IP_$($Address)" -PrinterHostAddress $Address
  Add-Printer -Name $Name -PortName "IP_$($Address)" -DriverName $DriverName
}


$Printers = @{
    "192.168.1.5"="Office Printer";
    "192.168.1.6"="Aux Office Printer";
}

# Setup each of the printers
foreach($Printer in $Printers.GetEnumerator()) {
  Install-Printer -Address $Printer.Name -Name $Printer.Value -DriverName "HP Universal Printing PCL 6"
}

Putting it all together

Get the full script which includes additional features to remove other printers and set a default on GitHub.


I use this script and many others on Atera. If you're looking for a solid RMM and PSA solution without the headache of dealing with per-device pricing, give Atera a try.