Skip to content

Restart-PrintJob

Print Management: Restarts 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 }
        Restart-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 restarted on printer $PrinterName on $ComputerName"
    }
    catch { throw }
    finally { if ($null -ne $cim) { Remove-CimSession $cim -ErrorAction SilentlyContinue } }
}

Name of the printer on which to restart the print job.

ID of the print job to restart.

Name of the computer on which to restart the print job.

User account that has permission to perform this action.

An interactive directory of PowerShell scripts.