Script: Set Default Printer (GUI)

Printers are not the easiest things to install and manage for experienced IT professionals, let alone for the typical end user.

There was a need for the clients I interact with to be able to quickly identify which printer is their default and to be able to switch simply. Without having to worry about navigating the windows settings.

The below solution may not have the sharpest look but it is functional and can be tidied up if you have the need and time to do it.

The solution is a PowerShell script that when run will open a Windows Form. It will list all of the installed printers on a machine and also display the current default Printer.

The end-user can select from the list of printers and click “Set Default” to change the default to the selected printer.

Click here to download a zipped folder that contains a compiled exe of the script.
This makes it simple for the end-user to just click to run, instead of dealing with needing to know how to run a script.
You can also then store it somewhere centrally and deploy a shortcut to it with group policy for easy access to all users.

$Printers = Get-WmiObject -Class Win32_Printer | Select-Object -ExpandProperty name
$currentPrinter = Get-WmiObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" | Select-Object -ExpandProperty name

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationFramework

$Form = New-Object system.Windows.Forms.Form
$Form.Text                      = "Default Printer Setup"
$Form.BackColor                 = "#d7ebfe"
$Form.TopMost                   = $true
$Form.Width                     = 800
$Form.Height                    = 500
$Form.StartPosition             = "CenterScreen"
$Icon                           =  [System.Drawing.Icon]("$PSScriptRoot\logo.ico")
$Form.Icon                      = $Icon

$lb_availablePrinters = New-Object
$lb_availablePrinters.Text = "Available Printers"
$lb_availablePrinters.AutoSize = $true
$lb_availablePrinters.Width = 25
$lb_availablePrinters.Height = 10
$lb_availablePrinters.location = new-object system.drawing.point(8,117)
$lb_availablePrinters.Font = "Verdana,25"

$lb_defaultPrinter = New-Object
$lb_defaultPrinter.Text = "Current Default Printer"
$lb_defaultPrinter.AutoSize = $true
$lb_defaultPrinter.Width = 25
$lb_defaultPrinter.Height = 10
$lb_defaultPrinter.location = new-object system.drawing.point(372,117)
$lb_defaultPrinter.Font = "Verdana,25"

$lb_heading = New-Object
$lb_heading.Text = "Default Printer Setup"
$lb_heading.AutoSize = $true
$lb_heading.Width = 25
$lb_heading.Height = 10
$lb_heading.location = new-object system.drawing.point(156,28)
$lb_heading.Font = "Verdana,30,style=Underline"

$bt_close = New-Object
$bt_close.Text = "Close"
$bt_close.ForeColor = "#251c53"
$bt_close.Width = 145
$bt_close.Height = 33
$bt_close.location = new-object system.drawing.point(462,374)
$bt_close.Font = "Verdana,15,style=Bold"

$lb_printer = New-Object
$lb_printer.Text = "$currentPrinter"
$lb_printer.AutoSize = $true
$lb_printer.Width = 270
$lb_printer.Height = 50
$lb_printer.location = new-object system.drawing.point(442,186)
$lb_printer.Font = "Verdana,15"

$lstBX_printers = New-Object
$lstBX_printers.Width = 270
$lstBX_printers.Height = 144
$lstBX_printers.location = new-object system.drawing.point(20,186)
foreach ($Printer in $Printers)
    $Global:currentPrinter = $lstBX_printers.SelectedItem

$bt_setDefault = New-Object
$bt_setDefault.Text = "Set Default"
$bt_setDefault.ForeColor = "#251c53"
$bt_setDefault.Width = 145
$bt_setDefault.Height = 33
    (New-Object -ComObject WScript.Network).SetDefaultPrinter($Global:currentPrinter)
    $lb_printer.Text = "$Global:currentPrinter"
$bt_setDefault.location = new-object system.drawing.point(121,373)
$bt_setDefault.Font = "Verdana,15,style=Bold"


Leave a Reply

Your email address will not be published.

Copyright CTlogic 2022