As of Windows 8.1 / Server 2012 R2 there is one beautiful cmdlet -Add-PrinterDriver. It dramatically simplifies driver/printer installation.
Naturally you will be tempted to install a driver from an .inf file like this:
Add-PrinterDriver -Name "HP Universal Printing PCL 6" -InfPath "C:\Install\HP\hpcu160u.inf"
But you will be blamed:
Add-PrinterDriver: One or more specified parameters for this operation has an invalid value.
So it does not work as you/we may think. Sigh… So then what it is used for?
The documentation of Add-PrinterDriver is not very clear. It just says:
Installs a printer driver on the specified computer
Add-PrinterDriver [-Name] <String> [[-InfPath] <String> ]
Hmm…isn’t strange that you can specify name and *eventually* path to the inf file?
Here is the catch: the driver package should already be present in Windows’ driver store!So let’s re-read the docs again:
Add-PrinterDriver:Installs a printer driver [from the driver store] on the specified computer.
-Name:Specifies the name of the printer driver [as seen in the driver store].
-InfPath:Specifies the path to the printer driver INF file in the driver store.
Now that makes sense, right?
The Driver store is something like a repository for drivers. Actual installation gets the required files from Driver store, place them according to the installation rules (usually in System32\Drivers) and performs driver registration (in the registry).
So the next question is how do we actually add a printer driver package to the Driver store?
The answer is simple – use the built in PNPUTIL tool:
pnputil /add-driver x:\driver.inf
So the workflow for installing a printer with its driver will be:
- Add printer’s driver in the Driver store
- Install the printer
- Add-PrinterDriver interncally usesMSFT_PrinterDriver::Add().
- If your drivers are located on a shared folder (i.e. using UNC path) your script may encounter the security pop-up (aka Attachment Manager’s warning). You can overcome this by temporarily settingSEE_MASK_NOZONECHECKS environment variable to value “1” (without quotes) then add printer drivers.