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.
Batch Script
Add a network printer
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
1 |
Add-Printer -ConnectionName \\printServer\printerName |
Replace ‘printServer’ and ‘printerName’ with your organization’s printer server and required printer name.
Add a local printer
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
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:
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:
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:
1 |
Get-PrintConfiguration -PrinterName "Microsoft XPS Document Writer" |
Replace ‘Microsoft XPS Document Writer:’ with the required printer name to return printer configurations.
All printers:
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:
1 |
Get-Printer |
Returns the complete list of printers and printer connections on the device.
Printer ports:
1 |
Get-PrinterPort |
Returns the complete list of printer ports on the local device.
Get the printer information
Specific printer:
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:
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.
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:
1 |
Get-PrinterProperty -PrinterName "PrinterName" |
Returns the list of properties for the printer mentioned in the ‘PrinterName’ field.
All printers:
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:
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:
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:
1 |
Remove-PrinterPort -Name "LocalPort:" |
Replace ‘LocalPort:’ with the name of the printer port you want to remove from the device.
Rename a printer
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
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.