Public/Get-SpecPrinterDriver.ps1

Function Get-SpecPrinterDriver {
    <#
    .SYNOPSIS
    This PowerShell function retrieves information about a specified printer driver.
 
    .DESCRIPTION
    The Get-SpecPrinterDriver function retrieves detailed information about a printer driver by its name. It uses the Get-PrinterDriver cmdlet to retrieve the driver information. If the driver is found, it returns a success code of 400. If the driver is not found, it returns an error code of 401. If an unexpected error occurs during the process, it returns an error code of 402.
 
    .PARAMETER printDriverName
    Specifies the name of the printer driver to retrieve information about. This parameter is mandatory.
 
    .EXAMPLE
    Get-SpecPrinterDriver -printDriverName "HP Universal Printing PCL 6"
 
    This example retrieves information about the "HP Universal Printing PCL 6" printer driver.
 
    .INPUTS
    None. You cannot pipe objects to this function.
 
    .OUTPUTS
    Returns an array of codes including if any errors occurred during the process. The following codes can be returned:
    400 - The printer driver was found.
    401 - The printer driver was not found.
    402 - An unknown error occurred. (Check the error message for more information.)
 
 
    .NOTES
    Author: owen.heaume
    Version: 1.0
    #>

    [cmdletbinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]$printDriverName
    )

    try {
        Write-verbose "Getting printer driver $printDriverName"
        Get-PrinterDriver -Name $printDriverName -ErrorAction Stop -ev x
        Write-verbose "Got printer driver $printDriverName"
        return 400
    } catch {
        Write-Warning -Message "Failed to get printer driver $printDriverName"
        if ($x -match "No MSFT_PrinterDriver objects found with property 'Name' equal to") {
            Write-Warning "A driver named $printDriverName does not exist"
            return 401
        } else {
            Write-Warning "The error message was: $x"
            return 402
        }
    }
}