# 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 | Where-Object { $_ -notmatch "EPIC"}
    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 }

    $jobs = @()
    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)" -ParentId 1

        if (-not (Test-Connection $comp -Count 1)) {
            Write-Output "$printer | $comp Offline"
            continue
        }

        $jobs += Invoke-Command -ScriptBlock { Remove-Printer ${using:printer} } -ComputerName $comp -SessionOption (New-PSSessionOption -NoMachineProfile -OpenTimeout 60) -AsJob
        # Remove-Printer $printer -ComputerName $comp -AsJob

        # Write-Output "$printer | $comp Job Sent"
    }
    Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -PercentComplete (100*$i / $comps.Length) -CurrentOperation "Awaiting results..." -ParentId 1
    $jobs | Wait-Job | Select-Object Location,State
    Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -Completed
}