Get-PrinterDriver
Print Management: Gets the specified printer driver from the computer.
#Requires -Version 5.1
#Requires -Modules PrintManagement
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$DriverName,
[string]$ComputerName,
[pscredential]$AccessAccount,
[ValidateSet('*', 'Name', 'Description', 'InfPath', 'ConfigFile', 'MajorVersion', 'PrinterEnvironment', 'PrintProcessor')]
[string[]]$Properties = @('Name', 'Description', 'InfPath', 'ConfigFile', 'MajorVersion', 'PrinterEnvironment', 'PrintProcessor')
)
Process {
try {
if ($Properties -contains '*') { $Properties = @('*') }
if ([System.String]::IsNullOrWhiteSpace($ComputerName)) { $ComputerName = [System.Net.DNS]::GetHostByName('').HostName }
$cim = if ($null -eq $AccessAccount) { New-CimSession -ComputerName $ComputerName -ErrorAction Stop }
else { New-CimSession -ComputerName $ComputerName -Credential $AccessAccount -ErrorAction Stop }
$driver = Get-PrinterDriver -CimSession $cim -Name $DriverName -ComputerName $ComputerName -ErrorAction Stop |
Select-Object $Properties | Sort-Object Name
$driver | ForEach-Object { $_ | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru }
Write-Output $driver
}
catch { throw }
finally { if ($null -ne $cim) { Remove-CimSession $cim -ErrorAction SilentlyContinue } }
}Name of the printer driver to retrieve.
Name of the computer from which to retrieve the printer driver.
User account that has permission to perform this action.
List of properties to expand; use * for all properties.