Public/Printing/Get-PrinterDriverName.ps1

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


FUNCTION Get-PrinterDriverName {
    <#
    .SYNOPSIS
    Retrieves the driver name for a specified printer.
 
    .DESCRIPTION
    This function retrieves the driver name for a specified printer. If the printer is found, it retrieves and displays the driver name and version. If the printer or driver is not found, it displays an appropriate message and returns $null.
 
    .PARAMETER Name
    Specifies the name of the printer for which to retrieve the driver name.
 
    .EXAMPLE
    Get-PrinterDriverName -Name "Printer1"
    Retrieves and displays the driver name and version for the printer named "Printer1".
 
    .INPUTS
    System.String. The function accepts a string input for the printer name.
 
    .OUTPUTS
    System.String. Returns the driver name if found, otherwise returns $null.
 
    .NOTES
    Ensure you have the necessary permissions to query printer and driver information.
    #>


    param (
        [string]$Name
    )

    $printer = Get-Printer -Name $Name
    if ($printer) {
        $driver = Get-PrinterDriver -Name $printer.DriverName
        if ($driver) {
            Write-Host "Driver for printer '$Name': $($driver.Name)"
            RETURN $driver.Name
        } else {
            Write-Host "Driver for printer '$Name' not found."
            RETURN $null
        }
    } else {
        Write-Host "Printer '$Name' not found."
        RETURN $null
    }
}