37 lines
1.4 KiB
PowerShell
37 lines
1.4 KiB
PowerShell
Start-Transcript -Path c:\windows\temp\printers.log
|
|
#Read printers.csv as input
|
|
$Printers = Import-Csv .\drivers.csv
|
|
|
|
#Add all printer drivers by scanning for the .inf files and installing them using pnputil.exe
|
|
$infs = get-childitem -Path . -Filter "*.inf" -Recurse -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Fullname
|
|
|
|
$totalnumberofinfs = $infs.Count
|
|
$currentnumber = 1
|
|
Write-Host ("[Install printer driver(s)]`n") -ForegroundColor Green
|
|
Foreach ($inf in $infs) {
|
|
Write-Host ("[{0}/{1}] Adding inf file {2}" -f $currentnumber, $totalnumberofinfs, $inf) -ForegroundColor Green
|
|
try {
|
|
c:\windows\sysnative\Pnputil.exe /a $inf | Out-Null
|
|
}
|
|
catch {
|
|
try {
|
|
c:\windows\system32\Pnputil.exe /a $inf | Out-Null
|
|
}
|
|
catch {
|
|
C:\Windows\SysWOW64\pnputil.exe /a $inf | Out-Null
|
|
}
|
|
}
|
|
$currentnumber++
|
|
}
|
|
|
|
#Add all installed drivers to Windows using the CSV list for the correct names
|
|
$totalnumberofdrivers = ($printers.drivername | Select-Object -Unique).count
|
|
$currentnumber = 1
|
|
Write-Host ("`n[Add printerdriver(s) to Windows]") -ForegroundColor Green
|
|
foreach ($driver in $printers.drivername | Select-Object -Unique) {
|
|
Write-Host ("[{0}/{1}] Adding printerdriver {2}" -f $currentnumber, $totalnumberofdrivers, $driver) -ForegroundColor Green
|
|
Add-PrinterDriver -Name $driver
|
|
$currentnumber++
|
|
}
|
|
|
|
Stop-Transcript |