1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Windows Powershell/Command Prompt check default printer

Discussion in 'Software' started by noizdaemon666, 8 Sep 2016.

  1. noizdaemon666

    noizdaemon666 I'm Od, Therefore I Pwn

    Joined:
    15 Jun 2010
    Posts:
    6,095
    Likes Received:
    803
    Hi guys,

    I have a Windows PC at work which keeps changing its default printer. I know how to change the default printer using powershell, but I'd like it to sit in the background and everytime it changes, change it back.

    I'm guessing this is really simple, but it's too early for my brain right now :D
     
  2. deathtaker27

    deathtaker27 Modder

    Joined:
    17 Apr 2010
    Posts:
    2,238
    Likes Received:
    186
    This is rather quick but seems to work:

    Code:
    #Set printer name
    $printerName = "\\server.domain.com\printer-name" #can be got from $printers below
    
    #Get the infos of all printer
    $Printers = Get-WmiObject -Class Win32_Printer
    Write-Verbose "Get the specified printer info."
    $Printer = $Printers | Where{$_.Name -eq "$PrinterName"}
    
    If($Printer)
    {
    Write-Verbose "Setting the default printer."
    $Printer.SetDefaultPrinter() | Out-Null
    
    Write-Host "Successfully set the default printer."
    }
    Else
    {
    Write-Warning "Cannot find the specified printer."
    }
    
     
  3. dynamis_dk

    dynamis_dk Grr... Grumpy!!

    Joined:
    23 Nov 2005
    Posts:
    3,762
    Likes Received:
    339
    I did this at work this week as part of an installer, I used:

    (New-Object -ComObject WScript.Network).SetDefaultPrinter('PRINTER NAME IN HERE')

    Is running as a task an option for you? Maybe triggered from an event log entry for a change of default printer? I'm not sure if there is a logging option for default printer changes mind so just a thought.

    Just wondering, this PC at work isn't Windows 10 is it?

    The Windows 10 option to manage default printer has just been disabled globally at my place as it was causing issues where we install things such as PDF viewers etc stealing being the default and we like the mono printers to be default :)
     
    Last edited: 9 Sep 2016
  4. Flibblebot

    Flibblebot Smile with me

    Joined:
    19 Apr 2005
    Posts:
    4,828
    Likes Received:
    295
    Doesn't Windows 10 also have an option where it automatically changes the default printer to the last printer used? IIRC, this is turned on by default (it's in Settings->Devices->Let Windows manage my default printer)
     
  5. RedFlames

    RedFlames ...is not a Belgian football team

    Joined:
    23 Apr 2009
    Posts:
    15,417
    Likes Received:
    3,010
    yes it does... in Settings > Devices > Printers & Scanners
     
  6. Flibblebot

    Flibblebot Smile with me

    Joined:
    19 Apr 2005
    Posts:
    4,828
    Likes Received:
    295
    Most. Annoying. Setting.
     
  7. noizdaemon666

    noizdaemon666 I'm Od, Therefore I Pwn

    Joined:
    15 Jun 2010
    Posts:
    6,095
    Likes Received:
    803
    It is a Windows 10 PC so I'll have a scout about and see what's what. Cheers chaps :)
     

Share This Page