Adding printer drivers with Endpoint Manager and PowerShell

Printers and their drivers, not always the most fun part of IT 😉 Since PrintNightMare it has become more difficult for users to add printers to their workstation, this blogpost describes how you can add printers using Endpoint Manager and PowerShell in a easy way.

Getting your drivers ready

What I usually experience from my clients is that they have a Printserver with all the printers published on that with the correct drivers. They want to add those to their AzureAD joined Endpoint Manager devices to continue using those drivers and settings. In a previous blogpost I described how to add printers with their configuration to a workstation (Link to article) , that method depends on having the drivers installed correctly.

You can check the printserver for what type of driver you use and where it’s stored if you don’t have the original driver package. In Print Management you can see the driver in the Drivers tab below your Printserver name, right-click for properties and you can see in what DriverStore directory it has been saved (Driver path)

Copy all the files in that directory to a folder on your hard drive and repeat this for all drivers. In the drivers pane you can also see the Inf path. Make note of the .inf file being used and create a CSV file with the Name and the directory containing the driver files together with the .inf file. This should look something like this:

Name,Path
Canon Generic Plus PCL6,Canon\C5840i\GPlus_PCL6_Driver_V240_32_64_00\x64\Driver\cnp60ma64.inf
Canon Generic Plus PS3,Canon\C165\GPlus_PS3_Driver_V240_32_64_00\x64\Driver\cns30ma64.inf
HP ColorLaserJet MFP M278-M281 PCL-6 (V4),HP\HP ColorLaserJet MFP M278-M281 PCL-6 (V4)\hpzead2a4_x64.inf
HP DesignJet Universal Print Driver HPGL2(v5.9.0),HP\HP Designjet Universal\win-x64-hpgl2-drv\hpi91edx.inf
HP LaserJet M507 PCL-6 (V4),HP\M507\HP_LJM507\HP_LJM507_V4\hpkoca2a4_x64.inf

Scripts for installing

Below are the files that you can use to create a .intunewin package for deploying the drivers, I use a install.cmd and a uninstall.cmd for starting the PowerShell scripts:

Install.cmd

powershell.exe -executionpolicy bypass .\install_printerdrivers.ps1

Uninstall.cmd

powershell.exe -executionpolicy bypass .\remove_printerdrivers.ps1

Install_Printerdrivers.ps1

$drivers = Import-Csv .\Drivers.csv -Delimiter ','
foreach ($driver in $drivers) {
    C:\Windows\Sysnative\pnputil.exe -a $driver.Path
    Start-Sleep -Seconds 5
    Add-PrinterDriver -Name $driver.name
}
New-Item -Path c:\programdata\customer\Printers\printers.txt -Force:$true -Confirm:$false

Remove_Printerdrivers.ps1

$drivers = Import-Csv .\Drivers.csv -Delimiter ','
foreach ($driver in $drivers) {
    Remove-PrinterDriver -Name $driver.name -Confirm:$false 
    Start-Sleep -Seconds 5
    C:\Windows\Sysnative\pnputil.exe -d $driver.Path
}
remove-Item -Path c:\programdata\customer\Printers -Recurse -Force:$true -Confirm:$false

Drivers.csv

Use the contents of the file that you made in the previous chapter, this should be something like this: (One printer per line)

Name,Path
Canon Generic Plus PCL6,Canon\C5840i\GPlus_PCL6_Driver_V240_32_64_00\x64\Driver\cnp60ma64.inf
Canon Generic Plus PS3,Canon\C165\GPlus_PS3_Driver_V240_32_64_00\x64\Driver\cns30ma64.inf
HP ColorLaserJet MFP M278-M281 PCL-6 (V4),HP\HP ColorLaserJet MFP M278-M281 PCL-6 (V4)\hpzead2a4_x64.inf
HP DesignJet Universal Print Driver HPGL2(v5.9.0),HP\HP Designjet Universal\win-x64-hpgl2-drv\hpi91edx.inf
HP LaserJet M507 PCL-6 (V4),HP\M507\HP_LJM507\HP_LJM507_V4\hpkoca2a4_x64.inf

Detection

The detection is done on a c:\programdata\customer\printers\printers.txt file, use a File of folders exists rule on that. (Replace customer for your actual customer of course 😉 )

Deployment

With all the files in one directory, use intunewinapputil.exe to create a .intunewin package from that. Add the package to your Endpoint Manager environment using install.cmd and uninstall.cmd for installation and removal together with the detection as mentioned above. Deploy it to a test client, check if all drivers are installed correctly and deploy it to your other users.

Download the script(s) from GitHub here

One thought on “Adding printer drivers with Endpoint Manager and PowerShell

  1. Pingback: Blogpost – Adding printer drivers to Endpoint Manager using PowerShell – 247 TECH

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.