Powershell add printer and drivers

posted in: Uncategorized 0

This small script automatically add a driver and a printer to Windows 10

$portIP = "192.168.x.x"
$printName = "..."
$printDriverName = "..."
$inf = "\\server\...\....inf"

$shell = New-Object -Com WScript.Shell
$portName = "IP_$portIP"

$cmd = "pnputil.exe -i -a ""$inf"""
iex $cmd
Add-PrinterDriver -Name $printDriverName

# Port
$portExists = Get-Printerport -Name $portname -ErrorAction SilentlyContinue
if (-not $portExists) {
  Add-PrinterPort -name $portName -PrinterHostAddress $portIP

# Printer
$printDriverExists = Get-PrinterDriver -name $printDriverName -ErrorAction SilentlyContinue

if ($printDriverExists) {
	Add-Printer -Name $printName -PortName $portName -DriverName $printDriverName
	Write-Warning "Printer Driver not installed"

Leave a Reply

Your email address will not be published. Required fields are marked *

four × four =