Public/Printing/Remove-PrinterByName.ps1

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


FUNCTION Remove-PrinterByName {
    <#
    .SYNOPSIS
    Removes a specified printer by name.
 
    .DESCRIPTION
    This function removes a specified printer by name. If the removal is successful, it displays a confirmation message. If the removal fails, it displays an error message and returns $null.
 
    .PARAMETER Name
    Specifies the name of the printer to be removed.
 
    .EXAMPLE
    Remove-PrinterByName -Name "Printer1"
    Removes the printer named "Printer1".
 
    .INPUTS
    System.String. The function accepts a string input for the printer name.
 
    .OUTPUTS
    System.Object. Returns the result of the Remove-Printer cmdlet if successful, otherwise returns $null.
 
    .NOTES
    Ensure you have the necessary permissions to remove printers.
    #>


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

    process {
        try {
            $results = Remove-Printer -Name $Name -ErrorAction Stop
            Write-Host "Printer '$Name' removed successfully."
            RETURN $results
        } catch {
            Write-Host "Failed to remove printer '$Name'. Error: $_"
            RETURN $null
        }
    }
}