Category filter

Script to manage Printers on Windows 10 devices

Many organizations require printers for their daily works. Manually adding printers to employees’ devices is a tedious task. The installation and configuration procedure can be automated to save time and make the process easier. You can manage printers on Windows 10 devices remotely by executing custom scripts via Hexnode.

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

Batch Script

Add a network printer

Replace ‘servername’ and ‘Serverprinter’ with your organization’s printer server and required printer name.

rundll32 : Loads and runs 32-bit dynamic-link libraries (DLLs).

printui.dll : It is the executable file that contains the functions used by the printer configuration dialog boxes.

/in : Connects to a remote printer.

/n : Specifies the printer name.

PowerShell Script

Add a network printer

Replace ‘printServer’ and ‘printerName’ with your organization’s printer server and required printer name.

Add a local printer

Execute this command to add a printer ‘MXDW’ using the ‘Microsoft XPS Document Writer’ driver and the ‘portprompt:’ to the local computer. Replace the parameters as per your requirement.

Add a printer driver

Replace ‘Microsoft XPS Document Writer’ with the name of the printer driver you want to install on the device.

Create a printer port

Local printer port:

Replace ‘LocalPort:’ with the name of the local printer port you want to create on the device.

TCP printer port:

Replace ‘TCPPort:’ with the name of the TCP printer port you want to create on the device along with the required IP address instead of ‘192.168.100.100’.

Get the printer configuration

Specific printer:

Replace ‘Microsoft XPS Document Writer:’ with the required printer name to return printer configurations.

All printers:

$Printers variable gets the printer details, loops through all the printers and displays the printer configurations.

Get the list of printers and printer ports

Printers:

Returns the complete list of printers and printer connections on the device.

Printer ports:

Returns the complete list of printer ports on the local device.

Get the printer information

Specific printer:

Replace ‘Microsoft XPS Document Writer’ with the required printer name to retrieve information about the specified printer.

Printer driver:

Replace ‘Microsoft XPS Document Writer’ with the name of the required printer driver to display a summarized view.

Replace ‘Microsoft XPS Document Writer’ with the name of the required printer driver to display detailed information.

Get the printer properties

Specific printer:

Returns the list of properties for the printer mentioned in the ‘PrinterName’ field.

All printers:

$printers variable gets the printer details, loops through all the printers and displays the properties of installed printers on the device.

Remove printers, printer drivers and printer ports

Printers:

Replace ‘Microsoft XPS Document Writer’ with the name of the printer you want to remove from the device.

Printer driver:

Replace ‘Microsoft XPS Document Writer v1’ with the name of the printer driver you want to remove from the device.

Printer port:

Replace ‘LocalPort:’ with the name of the printer port you want to remove from the device.

Rename a printer

Replace ‘MXPS’ with the new name you want to assign and ‘Microsoft XPS Document Writer’ with the existing printer name.

Set configurations for the specified printer

The printer named ‘MXDW’ is set to print on a single side of A4 paper size.

-DuplexingMode You can input values such as OneSided, TwoSidedLongEdge, TwoSidedShortEdge

-PaperSize You can input several options such as Custom, Letter, Tabloid, Statement, Executive, A3, A4, A5, B4, B5, etc.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository