Printers and their drivers are not always the most fun part of IT 😉 Since PrintNightMare has become more difficult for users to add printers to their workstations, this blog post describes how you can easily add printers using Endpoint Manager and PowerShell.
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 blog post, 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 print server 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 driver’s pane, you can also see the Inf path. Make a note of the .inf file being used and create a CSV file with the Name and the directory containing the driver files and 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 you can use to create a .intunewin package for deploying the drivers. I use an install.cmd and a uninstall.cmd for starting the PowerShell scripts for the install.cmd I use the 32Bit PowerShell because of issues in calling the correct pnputil.exe
Install.cmd
C:\Windows\system32\WindowsPowerShell\v1.0\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) { try { c:\windows\sysnative\pnputil.exe -a $driver.Path } catch { try { c:\windows\system32\pnputil.exe -a $driver.Path } catch { C:\Windows\SysWOW64\pnputil.exe -a $driver.Path } } Start-Sleep -Seconds 5 } 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 if (Test-Path C:\Windows\Sysnative\pnputil.exe) { C:\Windows\Sysnative\pnputil.exe -d $driver.Path } else { C:\Windows\System32\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, and 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. Add the package to your Endpoint Manager environment using install.cmd and uninstall.cmd for installation and removal, together with the detection 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
Pingback: Blogpost – Adding printer drivers to Endpoint Manager using PowerShell – 247 TECH