Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We have a printer at work that is giving us problems. We have tried a few different solutions but when a user goes to print to this printer Windows 7 will sometimes display something like:

Windows needs to download and install a software driver from the ... computer

However the PC already has the correct driver. I tried changing a few settings in our group policy according to solutions that came up when I searched this problem but so far nothing has worked. For now I think it would be best to just have Windows reinstall the printer every time the user logs in.

I want the printer to be set to the default printer only if the user already had it set to be the default printer. How can I script this in PowerShell?

share|improve this question
    
"I want the printer to be set to the default printer only if the user already had it set to be the default printer. " This part is going to be impossible –  soandos Jul 17 '12 at 5:36
    
Not impossible, but would require a solution that many people would find unpalatable. You would need to periodically cache which printer is default. The most likely method would be to have a login script cache it to a text file. Then the restore script would just check there to see if it was the default. It means that if the user made the problem printer the default then the printer had the issue before the next login, the script would get it wrong. The OP would have to determine the likelyhood of this edge case. –  EBGreen Jul 23 '12 at 13:31
add comment

1 Answer

This can be achieved using WMI using the Win32_Printer class. Below is an example using powershell, you can do it in vbscript too.

You can adapt the script below to your own needs. The example assumes the driver is called "TOSHIBA e-STUDIO3510cSeriesPCL6"

$driver_name = 'TOSHIBA e-STUDIO3510cSeriesPCL6'

$printers = Get-WmiObject -Class win32_printer -Filter "DriverName='$driver_name'"

foreach ($printer in $printers) { 

    $printer.Delete()

    $return_status = (Invoke-WmiMethod -Class win32_printer -Name AddPrinterConnection -ArgumentList $printer.Name).ReturnStatus

    If ($return_status -eq 0 -and $printer.Default) { 

        (Get-WmiObject -Class win32_printer -Filter "Name='$($printer.Name)'").SetDefault() 
    }
}

What the script does is query which printers are using a particular driver and reinstalls them while maintaining the default printer status if needed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.