[CmdletBinding(SupportsShouldProcess = $true)] param( [string]$PrinterName, [string]$CsvPath, [int]$JobId = 0, [switch]$Cancel, [switch]$Force ) $ErrorActionPreference = 'Stop' if (-not (Get-Command -Name Get-Printer -ErrorAction SilentlyContinue)) { throw 'Команда Get-Printer недоступна. Нужна Windows 10 или 11.' } if (-not (Get-Command -Name Get-PrintJob -ErrorAction SilentlyContinue)) { throw 'Команда Get-PrintJob недоступна. Проверьте модуль PrintManagement.' } if ($PrinterName) { $printer = Get-Printer -Name $PrinterName -ErrorAction SilentlyContinue if (-not $printer) { throw "Принтер не найден: $PrinterName" } $printers = @($printer) } else { $printers = @(Get-Printer) } $jobs = New-Object System.Collections.Generic.List[object] foreach ($printer in $printers) { $items = Get-PrintJob -PrinterName $printer.Name -ErrorAction SilentlyContinue foreach ($item in $items) { $jobs.Add([pscustomobject]@{ Printer = $printer.Name Id = $item.Id Document = $item.DocumentName User = $item.UserName Status = [string]$item.JobStatus Submitted = $item.SubmittedTime Pages = $item.TotalPages }) } } if ($jobs.Count -eq 0) { Write-Host 'Очередь печати пуста.' } else { $jobs | Format-Table -AutoSize } if ($CsvPath) { $jobs | Export-Csv -LiteralPath $CsvPath -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $CsvPath" } if ($Cancel) { if (-not $PrinterName -or $JobId -le 0) { throw 'Для отмены укажите -PrinterName и -JobId.' } if (-not $Force) { throw 'Отмена меняет очередь печати. Добавьте -Force для подтверждения.' } if ($PSCmdlet.ShouldProcess("$PrinterName, задание $JobId", 'Отменить печать')) { Remove-PrintJob -PrinterName $PrinterName -ID $JobId Write-Host 'Задание отменено.' } }