Export-PrinterDrivers
Print Management: Exports printer drivers to a CSV file.
#Requires -Version 5.1
#Requires -Modules PrintManagement
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$ExportFile,
[string]$Delimiter = ';',
[ValidateSet('Unicode', 'UTF7', 'UTF8', 'ASCII', 'UTF32', 'BigEndianUnicode', 'Default', 'OEM')]
[string]$FileEncoding = 'UTF8',
[string]$ComputerName,
[pscredential]$AccessAccount
)
Process {
try {
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 }
$drivers = Get-PrinterDriver -CimSession $cim -ComputerName $ComputerName -ErrorAction Stop |
Select-Object Name, InfPath | Sort-Object Name
$csv = foreach ($d in $drivers) {
[PSCustomObject]@{ DriverName = $d.Name; ComputerName = $ComputerName; InfFilePath = $d.InfPath }
}
$csv | Export-Csv -Path $ExportFile -Delimiter $Delimiter -Encoding $FileEncoding -Force -NoTypeInformation -ErrorAction Stop
Write-Output "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") Printer drivers exported to: $ExportFile"
}
catch { throw }
finally { if ($null -ne $cim) { Remove-CimSession $cim -ErrorAction SilentlyContinue } }
}Path and filename of the CSV file to export.
Delimiter that separates the property values in the CSV file.
Type of character encoding used in the CSV file.
Name of the computer from which to export the printer drivers.
User account that has permission to perform this action.