Public/Add-SpecPrinterDriver.ps1
function Add-SpecPrinterDriver { <# .SYNOPSIS Adds a printer driver to the printer store. .DESCRIPTION The Add-SpecPrinterDriver function attempts to add a specified printer driver to the printer store. It checks if the driver exists on the system and provides verbose output for successful or unsuccessful driver addition. .PARAMETER printDriverName Specifies the name of the printer driver to add. .EXAMPLE Add-SpecPrinterDriver -printDriverName "DriverXYZ" Attempts to add the printer driver named "DriverXYZ" to the printer store. .OUTPUTS Returns an array of codes including if any errors occurred during the process. The following codes can be returned: 600 - Printer Driver successfully added 601 - The specified driver does not exist in the printer store 602 - 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 'Attempting to add driver to the printer store' Add-PrinterDriver -Name $printDriverName -ErrorAction Stop -ErrorVariable x Write-Verbose 'Printer Driver successfully added' return 600 } Catch { Write-Warning "Unable to add the driver to the store - does it exist on this system?" if ($x-match "The specified driver does not exist in the driver store.") { Write-Warning "The specified driver does not exist in the driver store." return 601 } else { Write-Warning "The error message was: $x" return 602 } } } |