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