[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] param( [Parameter(Mandatory = $true)] [string]$PrinterName, [string]$Message = 'Popov.Dev printer test', [switch]$Force ) $ErrorActionPreference = 'Stop' if (-not (Get-Command -Name Out-Printer -ErrorAction SilentlyContinue)) { throw 'Команда Out-Printer недоступна.' } if (-not (Get-Command -Name Get-Printer -ErrorAction SilentlyContinue)) { throw 'Команда Get-Printer недоступна. Нужна Windows 10 или 11.' } $printer = Get-Printer -Name $PrinterName -ErrorAction SilentlyContinue if (-not $printer) { throw "Принтер не найден: $PrinterName" } if ($printer.PrinterStatus -ne 'Normal') { Write-Warning "Статус принтера: $($printer.PrinterStatus)" } $lines = @( $Message ('Дата: ' + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')) ('Компьютер: ' + $env:COMPUTERNAME) ('Принтер: ' + $PrinterName) ) -join [Environment]::NewLine if ($Force -or $PSCmdlet.ShouldProcess($PrinterName, 'Напечатать тестовую страницу')) { $lines | Out-Printer -Name $PrinterName Write-Host "Тестовая страница отправлена: $PrinterName" }