PowerShell script to re-install printer, set to default if it was default












1















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
















1















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














1












1








1








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
















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?







windows-7 printer windows-server-2008 powershell network-printer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 17 '12 at 5:35









3498DB

15.8k114762




15.8k114762










asked Jul 16 '12 at 15:16









0xDECAFBAD0xDECAFBAD

612




612













  • "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



















  • "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

















"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





"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





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










1 Answer
1






active

oldest

votes


















0














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

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f449558%2fpowershell-script-to-re-install-printer-set-to-default-if-it-was-default%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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






























      0














      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




























        0












        0








        0







        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















        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














        share|improve this answer



        share|improve this answer








        edited May 12 '13 at 3:57

























        answered May 5 '13 at 16:25









        MFTMFT

        46236




        46236






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f449558%2fpowershell-script-to-re-install-printer-set-to-default-if-it-was-default%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Сан-Квентин

            8-я гвардейская общевойсковая армия

            Алькесар