Find Print Servers in a Domain
This will show all servers in the active directory with the print management role.
- Import-Module ActiveDirectory
- Get-ADObject -LDAPFilter "(&(&(&(uncName=*)(objectCategory=printQueue))))" -properties *|Sort-Object -Unique -Property servername | select servername
Powershell script to uninstall printer drivers and associated printer
{
write-host "Powershell version pre-5.1, running legacy script." $targetpc = read-host "Enter target PC name" $printernames = (Get-WmiObject Win32_PrinterDriver -ComputerName $targetpc).Name $count = 0 Foreach ($printername in $printernames)
{
if (!($printername.Contains('Microsoft')))
{
Write-Host "[$count] - $printername"
}
$count++
}
$input = read-host "Select number printer to remove" $printer = (($printernames[$input]).Split(","))[0] $version = (($printernames[$input]).Split(","))[1] $os = ((($printernames[$input]).Split(","))[2]).Split(" ")[1]
$printerdrivers = (Get-WmiObject Win32_PrinterDriver -ComputerName $targetpc).Name foreach ($printername in $printernames)
{
if($printer -eq $printername)
{
get-service -name spooler -ComputerName $targetpc
rename-item -path "hklm:\system\currentcontrolset\control\print\environments\windows x64\print processors\winprint" -newname winprint.old
Get-Service -Name "spooler" | Set-Service -Status Running
get-service -name spooler
rundll32 printui.dll,PrintUIEntry /dd /m "$printer" /h "$os" /v $version
get-service -name spooler | stop-service -force
rename-item -path "hklm:\system\currentcontrolset\control\print\environments\windows x64\print processors\winprint.old" -newname winprint
Get-Service -Name "spooler" | Set-Service -Status Running
}
}
$printernames = (Get-WmiObject -class win32_printer -ComputerName $targetpc -Recurse) $printernames
- clear variables
$count = $null $printernames = $null
}