Challenge

  • You have a new network (TCP/IP access), shared or local printer to install on a single endpoint.  If you are adding a  a network printer to a multiple endpoints and have Active Directory, use Group Policy as described here. 
  • You want the connection to be local to the endpoint.  You do NOT want to use a printer server queue located on a server.
  • You want to set the properties of the printer.  Example:  a shared drafting printer requires a 90 degree rotation and Super B (13 inch by 19 inch) paper
  • You want the printer to work for everyone who uses the endpoints, regardless of their user ID

Assumptions

  • You are using Active Directory from Server 2008 forward.  
  • Your endpoints are Windows 10 or later operating system computers joined to active directory

Solution 2 below works in an environment without Active Directory.  You must have user credentials with Administrator access on the target endpoint to remotely install the printer.

Solution

Note:  Group Policy can handle the distribution to the multiple endpoints as each endpoint is restarted.  Specifically, using Group Policy for distribution uses Group Policy Preferences. With the Group Policy solution, you do not not need to write a distribution script.  Learn more about the Group Policy solution for distribution to multiple endpoints here.

Just like installing a printer directly on an endpoint, you have steps to fulfill:

  1. install the printer driver
  2. Add the printer using PowerShell
    1. For a TCP/IP printer, that means supplying the printer network address
    2. For a network shared printer, that means supplying the Share name
      1. Solution 1:  use Add-Printer and the Print Server Role on a Server
      2. Solution 2:  Perform each Step with pnpUtil.exe and PowerShell
  3. Change the printer properties
  4. Bonus:  Run on a Remote Endpoint

Solution 1:  use Add-Printer and the Print Server Role on a Server

Install the printer driver – Using the Print Server Role on a Server to Install the Drivers to the Local Workstation

In this solution the server is the source for the printer driver.  

To avoid confusion:  just because you are setting up the printer on the server, does NOT mean that you will use the configuration on the server as a printer server.  While you could do that, the process described here does not create and use a server-based print server.  Instead, the server printer configuration provides a source for installing the drivers on the endpoint.  When the process is complete, the printer drivers reside on the endpoint.  The server could be powered off and the endpoint could still print.  The endpoint would not be able to do this if the endpoint was using a printer server operating on the powered-off server.

This implementation requires that you install the Print Server role on the server used for the Add-Printer command to source the printer drivers.  If the server does not have the Print Server role installed, I have detailed instructions on adding the role in the post:  Active Directory:  Add a Network Printer without using a Print Server.

Add the Printer Using PowerShell

Add-Printer -ConnectionName \\printserver\printername

All commands must be run in an elevated (Administrator) PowerShell session or, if invoked remotely, with Administrator credentials.

Solution 2:  Perform each Step with pnpUtil.exe and PowerShell

For an environment which does not have Active Directory and a server source for drivers.  You must have user credentials with Administrator access on the target endpoint to remotely install the printer.

Install the printer driver – Using pnpUtil.exe

The utility pnpUtil.exe is included in all Windows operating systems since Windows 7.  It is NOT a PowerShell command.  It will run in a PowerShell session. 

This step is required to enable adding printer drivers.  You must have unpacked and located the printer .inf settings for the printer.  

pnputil.exe /a "\\fileshare\HPPrinter\*.inf"

The location must be accessible from the target endpoint and contain the .inf settings.  This command will add the driver to the store at C:\Windows\System32\DriverStore. 

The printer driver can now be added.  The name for the driver must match the name in the .inf file.

Add-PrinterDriver -Name "HP OfficeJet 5200 series PCL-3" -InfPath "C:\Windows\System32\DriverStore\FileRepository\hpygid24_v4.inf_amd64_f312bf16a5228084\hpygid24_v4.inf"

Create the Printer Port

Add-PrinterPort -Name "<your port name>" -PrinterHostAddress "<the IP Of Printer>"

Install the Printer

Add-Printer -DriverName "HP OfficeJet 5200 series PCL-3" -Name "Printy" -PortName "Ports McGee"

Change the Printer Properties

If you are using these options, you hopefully do not have any special printing Defaults requirements.  A special requirement would be the default paper size.  A printer designed for drafting required that all prints be rotated 90 degrees.

This is a disadvantage to using PowerShell direct setup in preference to GPO setup.  With GPO setup, future changes made to the printing defaults on the server instance for the printer will be pushed out to the endpoints by GPO.  PowerShell does not have a similar ongoing mechanism.  

You can easily use the Set-PrintConfiguration to set properties such as:

  1. Collate
  2. Color (printing)
  3. DuplexingMode
  4. Paper Size

Set-PrintConfiguration has two properties, PrintCapabilitiesXML and PrintTicketXML, that you could theoretically alter to change printing defaults.  Documentation for how to do it (or if it would even work) is non-existent.

Set-PrinterProperty enables changing properties via property names, usually prefixed with ‘Config:’.  As with Set-PrintConfiguration, existence of documentation is whispered legend.

With Solution 1, you can delete and re-install with the most recent drivers.  Preferences may or may not be loaded from the server on install along with the drivers.  With Solution 2, you will need to make manual changes.  

Bonus:  Run on a Remote Endpoint

Find out how to setup a printer using PowerShell on another computer than where you’re running the commands by going here.

Resources

About the PowerShell Print Management Module – Microsoft Documentation

Using PowerShell to Install Printers | PDQ.com – a step-by-step walkthrough of using PowerShell to setup a Shared Name network printer.  It comprehensively covers the pitfalls of using PowerShell to setup a printer

PnPUtil Command Syntax – Microsoft Documentation – details about using the PNPutil.exe command to add the printer drivers (not a PowerShell command)

Setting “Printing defaults” through Powershell  – why you should use GPO to set printers from the server AND why you need to set the value to update

Installing printers with Intune & PowerShell – Provides scripts that, when run on the target endpoint, loads new printers.  This goes beyond the Add-Printer because it dismisses the UAC prompt that would stop an unattended install

WHAT ABOUT PRINTER DRIVERS – Has a comprehensive and detailed PowerShell script that ties together the solution described above, but with much more checking and a cleaner presentation (and it works with InTune)

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>