Public/Printing/Repair-Printer.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Repair-Printer {
    <#
    .SYNOPSIS
    Repairs a specified printer by restarting the Print Spooler service and clearing print jobs.
 
    .DESCRIPTION
    This function repairs a specified printer by restarting the Print Spooler service and clearing all print jobs for the printer. It displays a message indicating the repair process.
 
    .PARAMETER PrinterName
    Specifies the name of the printer to be repaired.
 
    .EXAMPLE
    Repair-Printer -PrinterName "Printer1"
    Repairs the printer named "Printer1" by restarting the Print Spooler service and clearing print jobs.
 
    .INPUTS
    System.String. The function accepts a string input for the printer name.
 
    .OUTPUTS
    None. The function does not return any output.
 
    .NOTES
    Ensure you have the necessary permissions to manage print jobs and restart services.
    #>


    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
        [string]$PrinterName
    )

    process {
        Write-Host "Repairing printer '$PrinterName'..."

        # Restart the Print Spooler service
        Restart-PrintSpooler | Out-Null

        # Clear print jobs for the specified printer
        Clear-PrintJobs -Name $PrinterName | Out-Null

        RETURN $null
    }
}