fb
Homepage 5 How-to Articles 5 How to Install and Remove Printer with PowerShell on Windows

How to Install and Remove Printer with PowerShell on Windows

Manage remote endpoints, deploy software and patches with Action1 cloud RMM solution.

Sign up and use free on up to 50 endpoints with no functionality limits or expiration.



January 3, 2020
Sometimes while installing or uninstalling a printer, you may face a wide range of unexpected errors:
  • It might be impossible to remove the printer from the system.
  • The printer cannot be uninstalled completely. 
  • New drivers fail to be installed.
  • After installation, the error The driver is not fully installed” or “Some functions will be unavailable” shows up.
However disturbing it may look at first glance, there is no need to panic since the worst-case scenario is to format the computer’s hard disk and install the operating system and all the required software. In this article, we will go through some typical commands for managing printers, ports, and print drivers on such operating systems as Windows 10, Windows 8.1, and Windows Server 2012 R2 / 2016 / 2019 by using PowerShell. You’ll also find how to add or remove network printers.

Let’s Get Acquainted with Powershell Module: PrintManagement

Along with the release of Windows 8.1 and Windows Server 2012 R2, Microsoft has unveiled a new version of PowerShell 4.0 (included in the Windows Management Framework 4.0), which significantly expanded a list of cmdlets for managing a Windows-based print server. To find out the whole list of cmdlets for managing printers, drivers, and print queues in the PrintManagement module on Windows 10 (PoSh v5), use the following command: Get-Command –Module PrintManagement
Step 1 to Work With Remote Network Printer is to use command Get Command Module PrintManagement

There are 22 PowerShell cmdlets in the PrintManagement module for managing printers, drivers, print ports, and queues:

  • Add-Printer — add (install) a new printer;
  • Add-PrinterDriver — install a new print driver;
  • Add-PrinterPort — create a print port;
  • Get-PrintConfiguration — print printer settings;
  • Get-Printer — display a list of printers installed on the computer;
  • Get-PrinterDriver — list the installed print drivers;
  • Get-PrinterPort — display a list of print ports;
  • Get-PrinterProperty — show printer properties;
  • Get-PrintJob — get a list of printer print jobs;
  • Read-PrinterNfcTag — get the required printer information from an NFC tag;
  • Remove-Printer — remove the printer;
  • Remove-PrinterDriver — remove a printer driver;
  • Remove-PrinterPort — remove a printer port;
  • Remove-PrintJob — delete a print job on a printer;
  • Rename-Printer — rename a printer;
  • Restart-PrintJob — restart a print job;
  • Resume-PrintJob — run a paused task;
  • Set-PrintConfiguration — printer configuration settings;
  • Set-Printer — update printer configuration;
  • Set-PrinterProperty — change printer properties;
  • Suspend-PrintJob — suspend a print job;
  • Write-PrinterNfcTag — write information to the NFC tag.

To get detailed information on the syntax of a specific command, type the following:

Get-Help cmdlet-name -Detailed

Examples of using commands:

Get-Help cmdlet-name -Examples

Now let’s look at a few examples of typical printer management scripts on Windows 10 from PowerShell.

Installing a Print Driver in the Driver Store

To list the print drivers installed in the Windows driver store, here’s the command:

Get-PrinterDriver

Next step to Work With Remote Network Printer is to use command Get PrinterDriver

To illustrate the process of installing a new print driver, let’s take a concrete example of setting up HP Universal Printing PCL 6. According to the documentation, the PowerShell command for adding a driver is:

Add-PrinterDriver -Name “HP Universal Printing PCL 6” -InfPath “C:\Distr\HP-pcl6-x64\hpcu118u.inf”

However, when you try your best to install a driver this way, an error appears:

Add-PrinterDriver : One or more specified parameters for this operation has an invalid value.

At line:1 char:1

+ Add-PrinterDriver -Name “HP Universal Printing PCL 6” -InfPath “C:\Di …

+ ~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (MSFT_PrinterDriver:ROOT/StandardCimv2/MSFT_PrinterDriver) [Add-PrinterDriver], CimException + FullyQualifiedErrorId : HRESULT 0x80070057,Add-PrinterDriver

It turns out the driver from the INF file can be added under one specific condition — only if the DriverStore driver storage contains it. Logically, using the Add-PrinterDriver command to install a driver not available in the system driver storage is impossible. To install the driver in DriverStore, you can use:

The PnPUtil.exe utility. The format is pnputil.exe -i -a C: \ Distr \ HP-pcl6-x64 \ hpcu118u.inf (installs a specific printer driver) or pnputil.exe -i -a C: \ Distr \ HP-pcl6-x64 \ * .inf (installs all the drivers found in the INF files of the specified directory):

Next step to Work With Remote Network Printer is to using utility pnputil

The Add-WindowsDriver cmdlet allows you to integrate drivers in an offline Windows image.

After adding a printer driver to the repository, you need to put the driver on the list of available print servers.

Add-PrinterDriver -Name “HP Universal Printing PCL 6”

use cmdlt Add PrinterDriver Name

Installing a New Printer Using Powershell

To create an IP port for printing on a network printer (here, you can specify both an IP address of the network printer and a name of the remote print server):

Add-PrinterPort -Name “IP_192.168.10.26” -PrinterHostAddress “192.168.10.26”

Before adding a port, you’d better check if it already exists or otherwise:

$portName = “IP_192.168.10.26”

$checkPortExists = Get-Printerport -Name $portname -ErrorAction SilentlyContinue

if (-not $checkPortExists) {

Add-PrinterPort -name $portName -PrinterHostAddress “192.168.10.26” }

To add a new printer in your operating system and then publish it, i.e. grant the shared access to it, you need to run the following command:

Add-Printer -Name hp2050_Office1_Buh -DriverName “HP Deskjet 2050 J510 series Class Driver” -PortName IP_192.168.10.26 -Shared -ShareName “hp2050_1_BUh” –Published

After executing the commands, you’ll see a new shared printer named hp2050_Office1_Buh on the list.

appear new printer buh

Listing Printers on a Print Server Using Powershell

 

How to display the full list of printers installed on this computer? Go by the instructions:

Get-Printer

As you can see in the picture below, the command displays such printers’ characteristics as Name, Type (local or network), Driver, Print Port. Also, we get information on whether printers are shared and published to AD or not (True or False).

Listing Printers on a Print Server Using Powershell

You can run most of the PrintManagement cmdlets to check out the status and manage printers, drivers, and print queues on remote computers. A remote computer’s or server’s name should correlate with the –ComputerName parameter.

By using PowerShell, you can get information about all the installed printers on a remote computer (print server) — just run the command:

Get-Printer -ComputerName msk-prnt1 | Format-List Name,DriverName

To display only a list of shared printers, use the command:

Get-Printer -ComputerName msk-prnt1 | where Shared -eq $true | fl Name

Connect a Network Printer from Powershell

To connect a printer from a print server, use the command:

Add-Printer -ConnectionName \\msk-prnt1\HPCL3020

Windows 10 uses the latest printer as the default printer. Do you want to use a fixed default printer? Then run the following command:

Set-ItemProperty -Path “HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows” -Name “LegacyDefaultPrinterMode” -Value 1 –Force

To set the default printer, go by these commands:

$wsnObj = New-Object -COM WScript.Network

$wsnObj.SetDefaultPrinter(%PrinterName%)

Remove Network Printer Using Powershell

To remove a printer, you need to run the following PowerShell command:

Remove-Printer -Name “hp2050_Office1_Buh”

You can remove a specific driver by using the Remove-PrinterDriver cmdlet:

Remove-PrinterDriver -Name “HP Universal Printing PCL 6”

How to Optimize Your Workload with Action1

After logging into the Action1 dashboard, in the Navigation pane (the left column), select Managed Endpoints and mark the device for you want to install printer. 

managed endpoints kb

Then click on the More Actions button and select the Run Command option

run command kb

In the window that opens, enter the command add-printer -name “ColorDell” -drivername “Dell Color Laser 1320c” -port “ToColor” to add a new printer.

add printer command - kb

In case you need to delete the printer use this command remove-Printer -Name ” ColorDell” 

remove printer command - kb

After clicking the Next Step button, you need to select the endpoints for which you are going to install or remove printer. To do this, click Add Endpoints and select the desired endpoint. 

select managed endpoints kb

Click Next Step and in the next step you can schedule the execution time of your command.Then click Finish

schedule and finish kb

What is the best RMM tool?

Staying competitive in the market is always a challenge, and loud words don’t do wonders for scaling up your business. But actions do! With Action1’s cloud-based RMM solution, your IT department will be keeping endpoints security in check, timely warning about potential threats and interventions.

Among the many principal features available through the Action1 centralized dashboard are:

  • patch management
  • software deployment
  • remote desktop
  • remote support
  • IT asset management
  • endpoint security
  • endpoint management
  • network monitoring

Read the TechRadar review of our product or be the judge — try out a free trial.

Related Articles

How To Delete User Profiles Remotely with PowerShell

When a user logs onto the computer for the first time (not via the network to access shared folders or printers), Windows creates a user profile. Among its contents are the NTUSER.DAT file (user profile settings), user-specific folders (My Documents, Desktop, etc.),...

About Action1 RMM

Action1 RMM is a cloud-based IT solution for remote monitoring and management, patching, and remote support.

Start your free two-week trial of Action1, or use RMM tools for free forever on 50 endpoints with no functionality limitations!



0 Comments

Submit a Comment

Your email address will not be published.

cloud patch management solutions action1

MSP Solution

Centralize endpoint management and boost efficiency of IT service delivery.

automated server patch management action compliance

Patch Management

Identify and deploy missing OS and third-party software updates.

cloud software deployment tools windows

Software Deployment

Distribute software and updates across managed endpoints.

software distribution tools software inventory action1

IT Asset Inventory

Keep a detailed inventory and manage hardware and software assets.

web client remote desktop

Remote Desktop

Support users via seamless remote desktop connection.

web based rdp client

Unattended Access

Provide administrative support and manage remote devices.

automated patch management action1

Endpoint Management

Run PowerShell, custom scripts, reboot computers and restart services.

API integrations action1

RESTful API

Integrate Action1 RMM to your IT ecosystem.

computer inventory tool for compliance

Reports and Alerts

Conduct endpoint security audits with comprehensive reporting.