# 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