Library / Windows endpoint

WIN-017 · Script

Add or Remove Network Printer

Adds or removes a shared print server printer or a direct IP printer silently, using parameters.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Two printer types are supported:

Shared A queue on a print server, for example \\print01\Room12-Copier. With -Scope Machine (default) the connection is added for every user who signs in to the device (per-machine connection, the same method as printui /ga). The print spooler is restarted so it shows up at the next sign-in. With -Scope User the connection is added for the current user only, so run it as that user.

  • IP: A printer reached directly by IP address or host name. Creates a Standard TCP/IP

port (RAW, port 9100 by default) and a local printer using -DriverName. The driver must already be installed, or supply -DriverInfPath to add it from an INF file first (for example a driver package copied to a share).

Report mode (default) lists the installed printers, ports and drivers and logs what -Action would do. Apply mode makes the change. -Action Remove for IP printers also removes the port when no other printer uses it.

Note: Windows Point and Print restrictions can block users from installing drivers from a print server. Running this script as SYSTEM installs the driver with admin rights, but some print servers need the driver to be present on the device first. Runs silently as SYSTEM from any RMM or Intune. No prompts.

Requirements

Windows PowerShell 5.1+, run as SYSTEM or local admin (Scope User: run as the user)

How to run it

  • Run as: SYSTEM or a local administrator
  • Run from: any RMM or MDM, Intune, a Group Policy startup script, a scheduled task, or an elevated PowerShell window
  • Script type: PowerShell, 64-bit
  • User interaction: none; the script never prompts
  • Timeout: 10 minutes (30 for Windows Update installs)

Settings

NameWhat it doesOptionsDefault
ModeReport (default) = check and log what would happen. Apply = make the change.Report, ApplyReport
ActionAdd (default) = install or update the printer. Remove = remove it.Add, RemoveAdd
PrinterTypeShared (default) or IP.Shared, IPShared
SharedPathUNC path of the shared queue for Shared, for example \\print01\Room12-Copier.
ScopeMachine (default) = all users of the device. User = the user running the script. Shared only.Machine, UserMachine
PrinterNameDisplay name for an IP printer, for example "Room 12 Copier".
PrinterAddressIP address or host name for an IP printer, for example 10.20.1.45.
PortNumberRAW TCP port for an IP printer. Default 9100.9100
DriverNameExact driver name for an IP printer, for example "HP Universal Printing PCL 6".
DriverInfPathOptional INF file to add to the driver store first, for example \\files\drivers\hpcu.inf.
LocationOptional location text for an IP printer, for example "Building A, Room 12".

Exit codes

  • 0 = Already in the requested state, or change done
  • 1 = Report: change needed. Apply: change failed or driver missing
  • 2 = Script error

Testing steps

  1. Run it first with the mode set to Report on one test device. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Run the script again with the same printer parameters and the opposite -Action (Remove after Add, Add after Remove). Drivers added to the driver store are left in place.

Version and change log

VersionDateChanges
1.0.0November 2026First release.