Stuck print jobs powershell
On a Windows print server, finds jobs that have been queued longer than a threshold (default 30 minutes). Posts the count + the oldest few so support staff can clear them or follow up with the user.
Placeholders only. Before running, replace
YOUR_URL with your capture endpoint's POST URL
.
(Open this page from your capture object to have these auto-filled.)
# print-queue-stuck.ps1 — jobs stuck in any print queue longer than N minutes.
$Url = "YOUR_URL/printqueue"
$StuckMinutes = 30
try {
$Jobs = Get-Printer -ErrorAction Stop | Get-PrintJob -ErrorAction SilentlyContinue
} catch {
$Body = (@{ hostname = $env:COMPUTERNAME; error = "$($_.Exception.Message)" }) | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $Url -Method Post -Body $Body -ContentType "application/json" -TimeoutSec 15 | Out-Null
exit 1
}
$Now = Get-Date
$Stuck = @($Jobs | Where-Object { $_.SubmittedTime -and (($Now - $_.SubmittedTime).TotalMinutes -gt $StuckMinutes) })
$Body = (@{
hostname = $env:COMPUTERNAME
total_jobs = $Jobs.Count
stuck_count = $Stuck.Count
threshold_min = $StuckMinutes
stuck_jobs = @($Stuck | Sort-Object SubmittedTime | Select-Object -First 10 | ForEach-Object {
@{
printer = "$($_.PrinterName)"
user = "$($_.UserName)"
document = "$($_.DocumentName)"
submitted = $_.SubmittedTime.ToString("o")
size_bytes = [int]$_.Size
}
})
}) | ConvertTo-Json -Compress -Depth 5
Invoke-RestMethod -Uri $Url -Method Post -Body $Body `
-ContentType "application/json" -TimeoutSec 15 | Out-Null
Recommended pairing
Add a capture.value check to this capture object.
json_path = stuck_count, op = >, threshold = 0 (severity: warn — operational nuisance, not an outage).
What is the filename?
print-queue-stuck.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com