Remove-PrintJob
Print Management: Removes a print job on the specified printer.
#Requires -Version 5.1
#Requires -Modules PrintManagement
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$PrinterName,
[Parameter(Mandatory = $true)]
[int]$JobID,
[string]$ComputerName,
[pscredential]$AccessAccount
)
Process {
try {
if ([System.String]::IsNullOrWhiteSpace($ComputerName)) { $ComputerName = [System.Net.DNS]::GetHostByName('').HostName }
$cim = if ($null -eq $AccessAccount) { New-CimSession -ComputerName $ComputerName -ErrorAction Stop }
else { New-CimSession -ComputerName $ComputerName -Credential $AccessAccount -ErrorAction Stop }
Remove-PrintJob -CimSession $cim -ComputerName $ComputerName -PrinterName $PrinterName -ID $JobID -ErrorAction Stop | Out-Null
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Print job $JobID removed from printer $PrinterName on $ComputerName"
}
catch { throw }
finally { if ($null -ne $cim) { Remove-CimSession $cim -ErrorAction SilentlyContinue } }
}Name of the printer from which to remove the print job.
ID of the print job to remove.
Name of the computer from which to remove the print job.
User account that has permission to perform this action.