Locate printer driver on multiple computers


A couple of weeks ago a bad printer driver where distributed to some of our clients. It was an universal driver so the impact was on nearly every printer of a specific brand and that brand  represents approximately fifty percent of our printers. We now needed to find out which computers had the faulty driver and to do so we searched every computer if it had a driver with the same driver version(do a get-printerdriver | select * and on property “driverversion” you will find a number) as the bad driver. Since not all of our 8000 clients are powered on or on our network we also exported all computers not answering on Test-Connection to a file that we can use later if we run the script again. After my college had run the script he ended up with two files, one with all computers with bad driver and one with computers not answering to test-connection.


$computers = Get-Content "C:\temp\datorer.txt"
$date = get-date -Format HH.mm
$outfile1 = "C:\temp\dosnt_answer $date.txt"
$outfile2 = "C:\temp\wrong_driver $date.txt"

foreach ($computer in $computers)

Write-Host "testar om $computer svarar"
$connection = Test-Connection $computer -Count 1 -ErrorAction SilentlyContinue
if ($connection -ne $null)
{Write-Host "$computer answering, checking driver."
$exists = Get-PrinterDriver -ComputerName $computer -ErrorAction SilentlyContinue | where driverversion -eq "1970930661982208"

if ($exists -ne $null)
{write-host "$computer has wrong driver"
Out-File -FilePath "c:\temp\fel_drivare.txt" -Append
{write-host "$computer doesn't have bad driver."
out-file -FilePath $outfile2 -Append -InputObject $computer
{write-host "$computer doesn´t answer"
out-file -FilePath $outfile1 -Append -InputObject $computer