# 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](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) via Hexnode.

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

 

Batch Script
------------

### Add a network printer

Batch script to add a network printer

rundll32 printui.dll,PrintUIEntry /in /n\\\\servername\\Serverprinter

   1

  rundll32 printui.dll,PrintUIEntry /in /n\\\\servername\\Serverprinter

   

 

  

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

Powershell script to add a network printer

Add-Printer -ConnectionName \\\\printServer\\printerName 

   1

  Add-Printer -ConnectionName \\\\printServer\\printerName 

   

 

  

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

### Add a local printer

Powershell script to add a local printer

Add-Printer -Name "mxdw 2" -DriverName "Microsoft XPS Document Writer v4" -PortName "portprompt:" 

   1

  Add-Printer -Name "mxdw 2" -DriverName "Microsoft XPS Document Writer v4" -PortName "portprompt:" 

   

 

  

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

Powershell script to add a printer driver

Add-PrinterDriver -Name " Microsoft XPS Document Writer" 

   1

  Add-PrinterDriver -Name " Microsoft XPS Document Writer" 

   

 

  

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:**

PowerShell script to create a local printer port

Add-PrinterPort -Name "LocalPort:" 

   1

  Add-PrinterPort -Name "LocalPort:" 

   

 

  

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

**TCP printer port:**

PowerShell script to create a TCP printer port

Add-PrinterPort -Name "TCPPort:" -PrinterHostAddress "192.168.100.100" 

   1

  Add-PrinterPort -Name "TCPPort:" -PrinterHostAddress "192.168.100.100" 

   

 

  

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:**

PowerShell script to get the printer configuration

Get-PrintConfiguration -PrinterName "Microsoft XPS Document Writer" 

   1

  Get-PrintConfiguration -PrinterName "Microsoft XPS Document Writer" 

   

 

  

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

**All printers:**

PowerShell script to get printer configuration for all printers

$Printers = Get-Printer \* Foreach ($Printer in $Printers){Get-PrintConfiguration -PrinterName $Printer.name} 

   1

2

  $Printers = Get-Printer \*

Foreach ($Printer in $Printers){Get-PrintConfiguration -PrinterName $Printer.name} 

   

 

  

$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:**

PowerShell script to get the list of printers

Get-Printer 

   1

  Get-Printer 

   

 

  

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

**Printer ports:**

PowerShell script to get list of printer ports

Get-PrinterPort 

   1

  Get-PrinterPort 

   

 

  

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

### Get the printer information

**Specific printer:**

PowerShell script to get information for specific printer

Get-Printer –Name “Microsoft XPS Document Writer” 

   1

  Get-Printer –Name “Microsoft XPS Document Writer” 

   

 

  

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

**Printer driver:**

PowerShell script to get info about printer driver

Get-PrinterDriver -Name "Microsoft XPS Document Writer" 

   1

  Get-PrinterDriver -Name "Microsoft XPS Document Writer" 

   

 

  

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

PowerShell script to get detailed info about printer driver

Get-PrinterDriver -Name "Microsoft XPS Document Writer" | Format-List 

   1

  Get-PrinterDriver -Name "Microsoft XPS Document Writer" | Format-List 

   

 

  

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

### Get the printer properties

**Specific printer:**

PowerShell script to get list of printer properties

Get-PrinterProperty -PrinterName "PrinterName" 

   1

  Get-PrinterProperty -PrinterName "PrinterName" 

   

 

  

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

**All printers:**

PowerShell script to get printer properties for all printers

$printers = get-printer \* foreach ($printer in $printers) { get-printerproperty -printerName $printer.name } 

   1

2

3

4

5

  $printers = get-printer \*

foreach ($printer in $printers)

{

 get-printerproperty -printerName $printer.name

} 

   

 

  

$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:**

PowerShell script to remove a printer

Remove-Printer -Name "Microsoft XPS Document Writer" 

   1

  Remove-Printer -Name "Microsoft XPS Document Writer" 

   

 

  

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

**Printer driver:**

PowerShell script to remove a printer driver

Remove-PrinterDriver -Name "Microsoft XPS Document Writer v1" 

   1

  Remove-PrinterDriver -Name "Microsoft XPS Document Writer v1" 

   

 

  

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

**Printer port:**

PowerShell script to remove a printer port

Remove-PrinterPort -Name "LocalPort:" 

   1

  Remove-PrinterPort -Name "LocalPort:" 

   

 

  

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

### Rename a printer

PowerShell script to rename a printer

Rename-Printer -Name "Microsoft XPS Document Writer" -NewName "MXPS" 

   1

  Rename-Printer -Name "Microsoft XPS Document Writer" -NewName "MXPS" 

   

 

  

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 

PowerShell script to set configurations for a printer

Set-PrintConfiguration -PrinterName "MXDW" -PaperSize A4 –DuplexingMode OneSided 

   1

  Set-PrintConfiguration -PrinterName "MXDW" -PaperSize A4 –DuplexingMode OneSided 

   

 

  

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.