Last active
February 16, 2024 14:44
-
-
Save sebastian13/563e80e7cece8957c98f4d64b0d3be84 to your computer and use it in GitHub Desktop.
How to install printers post PrintNightmare patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Deploy this via PDQ Deploy or run once as admin | |
# Delete all Network Printers | |
Get-WmiObject -Class Win32_Printer | where{$_.Network -eq 'true'} | ForEach-Object {$_.Delete()} | |
# Add Driver to the Store | |
# ... example for Sharp 1910a - 9.1.18.47 | |
pnputil.exe /a "\\nas01\tools\drivers\_Printers\MX_D54_PCL6_PS_1910a_German_64bit\German\PCL6\64bit\su0emdeu.inf" | |
# Install the Driver | |
# ... example for different Sharp Printers and driver from above | |
Add-PrinterDriver -Name "SHARP MX-2630N PCL6" -InfPath "C:\Windows\System32\DriverStore\FileRepository\su0emdeu.inf_amd64_c56a058ff3e3dc20\su0emdeu.inf" | |
Add-PrinterDriver -Name "SHARP MX-3060V PCL6" -InfPath "C:\Windows\System32\DriverStore\FileRepository\su0emdeu.inf_amd64_c56a058ff3e3dc20\su0emdeu.inf" | |
Add-PrinterDriver -Name "SHARP MX-3550N PCL6" -InfPath "C:\Windows\System32\DriverStore\FileRepository\su0emdeu.inf_amd64_c56a058ff3e3dc20\su0emdeu.inf" | |
Add-PrinterDriver -Name "SHARP MX-4060V PCL6" -InfPath "C:\Windows\System32\DriverStore\FileRepository\su0emdeu.inf_amd64_c56a058ff3e3dc20\su0emdeu.inf" | |
Add-PrinterDriver -Name "SHARP MX-B350W PCL6" -InfPath "C:\Windows\System32\DriverStore\FileRepository\su0emdeu.inf_amd64_c56a058ff3e3dc20\su0emdeu.inf" | |
Add-PrinterDriver -Name "SHARP MX-M3550 PCL6" -InfPath "C:\Windows\System32\DriverStore\FileRepository\su0emdeu.inf_amd64_c56a058ff3e3dc20\su0emdeu.inf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure Printers without Driver Install based on recursive group membership | |
# Use this script as a Logon Script for your users | |
# We use security groups to decide which printer should be configured and which should be set as default | |
# The groups usually have the format printer_* and may contain security groups e.g. department groups themself. | |
# Always Delete All Printers the User is allowed to delete | |
Get-WmiObject -Class Win32_Printer | where{$_.Network -eq 'true'} | ForEach-Object {$_.Delete()} | |
# Find Recursive Group Membership | |
$UserDN = ([adsisearcher]"samaccountname=$($env:USERNAME)").FindAll().properties.distinguishedname | |
$memberOf = ([adsisearcher]"(&(objectCategory=group)(objectClass=group)(member:1.2.840.113556.1.4.1941:=$UserDN))").FindAll().Properties.memberof -replace '^CN=([^,]+).+$','$1' | |
if($memberOf -like "printer_Example*") | |
{ | |
echo "Create Printer Port for Example" | |
Add-PrinterPort -Name "IP_10.0.3.24" -PrinterHostAddress "10.0.3.24" -ErrorAction SilentlyContinue | |
echo "Install the Printer for Example" | |
Add-Printer -DriverName "SHARP MX-2630N PCL6" -Name "Example" -PortName "IP_10.0.3.24" | |
if($memberOf -contains "printer_Example_default") | |
{ | |
echo "Set Example as Default" | |
(New-Object -ComObject WScript.Network).SetDefaultPrinter("Example") | |
} | |
} | |
# Thanks to | |
# https://www.pdq.com/blog/using-powershell-to-install-printers/#add-driver-to-the-store | |
# https://www.secuinfra.com/en/news/adsisearcher-resolve-groups-recursively/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing! From an IT Admin, thank you thank you thank you thank you! You have made my PrintNightmare year!