Working on a printer migration project, and one of the first steps was to clean up the existing print servers so that when running the migration. I wanted a way to contact remote print servers too. This script, once imported allows cleanup of remote print servers.
Requires Powershell 4, so run off a Windows 8/Windows Server 2012.
If targeting a Windows 2003 print server, it cannot perform the actual removal and will just list a number of errors. It does atleast highlight all of the drivers which are not in use though.
# ---------------------------------------------------------------------------------------------------------- # PURPOSE: Remove Printer Drivers which do not have any printers # # VERSION DATE USER DETAILS # 1 28/08/2014 Craig Tolley First version # 1.1 29/08/2014 Craig Tolley Moved getting printers into variable to improve performance. # # ---------------------------------------------------------------------------------------------------------- #Define the print server names. Function Remove-UnusedPrinterDrivers { Param ( #The name of the print server to clean up. [Parameter(Mandatory=$true)] [string]$PrintServerName ) #Get all of the printer drivers $Drivers = Get-PrinterDriver -ComputerName $PrintServerName $Printers = Get-Printer -ComputerName $PrintServerName ForEach($Driver in $Drivers) { $PrintersUsingDriver = ($Printers | Where {$_.DriverName -eq $Driver.Name} | Measure).Count Write-Host "Driver: $($Driver.Name) has $PrintersUsingDriver printers using it." If ($PrintersUsingDriver -eq 0) { Try { Remove-PrinterDriver -Name $Driver.Name -ComputerName $PrintServerName -ErrorAction Stop Write-Host " $($Driver.Name) has been removed." -ForegroundColor Green } Catch { Write-Host " Failed to remove driver: $($Driver.Name)" -ForegroundColor Red } } Write-Host "" } }
One thought on “Clean Up Unused Printer Drivers”