Fixed PrinterPurge

This commit is contained in:
Zachary Gorman 2024-12-13 14:45:17 -08:00
parent 2991af9df2
commit f02ec5d11d
4 changed files with 11 additions and 5 deletions

View file

@ -12,7 +12,7 @@
RootModule = 'Get-PC.psm1' RootModule = 'Get-PC.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '0.4.12' ModuleVersion = '0.4.13'
# Supported PSEditions # Supported PSEditions
# CompatiblePSEditions = @() # CompatiblePSEditions = @()

View file

@ -9,6 +9,7 @@ function Invoke-PrinterPurge ($printer) {
$res = Read-Host "$($comps.Length) computers found, remove $printer from all of them? (y/N)" $res = Read-Host "$($comps.Length) computers found, remove $printer from all of them? (y/N)"
if (-not ($res -match "^[yY]")) { return } if (-not ($res -match "^[yY]")) { return }
$jobs = @()
for ($i = 0; $i -lt $comps.Length; $i += 1) { for ($i = 0; $i -lt $comps.Length; $i += 1) {
$comp = $comps[$i] $comp = $comps[$i]
Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -PercentComplete (100*$i / $comps.Length) -CurrentOperation "$comp $i/$($comps.Length)" -ParentId 1 Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -PercentComplete (100*$i / $comps.Length) -CurrentOperation "$comp $i/$($comps.Length)" -ParentId 1
@ -20,9 +21,12 @@ function Invoke-PrinterPurge ($printer) {
continue continue
} }
Remove-Printer $printer -ComputerName $comp -AsJob $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-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 Write-Progress -Activity "Dispatching Remove-Printer Jobs for $printer" -Completed
} }

View file

@ -52,7 +52,7 @@
Manager=$manager Manager=$manager
Phone=$UserInfo.telephoneNumber Phone=$UserInfo.telephoneNumber
Email=$UserInfo.EmailAddress Email=$UserInfo.EmailAddress
Computers=$computerList Computers=$computerSCCM # User $computerList for more readable, $computerSCCM for more scriptable
LastLogon=$UserInfo.LastLogonDate LastLogon=$UserInfo.LastLogonDate
} }

View file

@ -1,7 +1,9 @@
Patch: Patch: 2024-12-13
-Add Powershell input pipeline support, unoptimized -Add Powershell input pipeline support, unoptimized
-Add CMDB fields now hold Spark warnings rather than printing to console in SCCM and normal queries -Add CMDB fields now hold Spark warnings rather than printing to console in SCCM and normal queries
-Add ports for DELL P2417H in Devices query -Add ports for DELL P2417H in Devices query
-Fix shsuser Computers field now uses raw data for scriptability rather than readability
-Fix PrinterPurge less finnicky, no longer dependent on printer spooler being accessible
Patch: 2024-10-24 Patch: 2024-10-24
-Fix Enable flag also removes workstation from Disabled Computers group -Fix Enable flag also removes workstation from Disabled Computers group