locked
Powershell Script to set Default printer IF.... RRS feed

  • Question

  • Hi, I'm looking for some help!

    I'm trying to write a script that will set the default printer to PRINTER3 if the current default printer is called PRINTER1, then exit powershell. I have 2500 of workstation in different locations to change so this would be very helpful if someone could help.

    Here is what I have so far:

    Set-Content C:\Temp\current.txt (Get-WmiObject -namespace root\cimv2 -Query “select * from Win32_Printer Where Default = TRUE” | select -ExpandProperty name)
    $current=get-content C:\Temp\current.txt
    if (-eq ($current - 'PRINTER1'))
    {
    (Get-WmiObject -Class Win32_Printer -Filter "Name='PRINTER3'").SetDefaultPrinter()
    }
    exit

    Thanks

    Mark


    • Edited by hud.81 Friday, December 22, 2017 9:55 AM amendment
    Friday, December 22, 2017 8:33 AM

All replies

  • One could probably change device name by R.clicking on device/properties,reset name..As for a script,go to TechNet

    script center,repository.

    https://gallery.technet.microsoft.com/scriptcenter

    Friday, December 22, 2017 9:15 PM
  • Hi Mark,

    Try this scripts:

    How to set default printer using PowerShell
    https://gallery.technet.microsoft.com/scriptcenter/How-to-set-default-printer-cf89670b

    For further script related question, it is recommended to post in script center for more help:
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.  Thank you for your understanding.


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, December 25, 2017 4:49 AM
  • I just post to check the current status of your issue, please let me know what you have done with our suggestions and whether your issue has been resolved. 

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, January 12, 2018 2:09 AM
  • $default = "PRINTER1"
    $newdefault = 'PRINTER3'
    $current = (Get-WmiObject -Query " SELECT name FROM Win32_Printer WHERE Default=$true").Name
    If ( $current -eq $default) {
    (New-Object -ComObject WScript.Network).SetDefaultPrinter($newdefault)
    }

    Use this WScript com object to set a default network printer

    Monday, April 16, 2018 10:46 AM