28 lines
1 KiB
PowerShell
28 lines
1 KiB
PowerShell
# Removes printer from all online computers. Useful when printer drivers
|
|
# change to force online users to install new drivers
|
|
function Invoke-PrinterPurge ($printer) {
|
|
$comps = HostnamesByPrinter($printer)
|
|
if (-not ($comps -is [array])) {
|
|
$comps = @($comps)
|
|
}
|
|
|
|
$res = Read-Host "$($comps.Length) computers found, remove $printer from all of them? (y/N)"
|
|
if (-not ($res -match "^[yY]")) { return }
|
|
|
|
for ($i = 0; $i -lt $comps.Length; $i += 1) {
|
|
$comp = $comps[$i]
|
|
Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -PercentComplete (100*$i / $comps.Length) -CurrentOperation "$comp $i/$($comps.Length)"
|
|
|
|
if ($comp -like "*EPIC*") { continue }
|
|
|
|
if (-not (Test-Connection $comp -Count 1)) {
|
|
Write-Output "$printer | $comp Offline"
|
|
continue
|
|
}
|
|
|
|
Remove-Printer $printer -ComputerName $comp -AsJob
|
|
|
|
Write-Output "$printer | $comp Job Sent"
|
|
}
|
|
Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -Completed
|
|
} |