Set default printer with PowerShell

Closely related to my previous post, this simple script uses a WScript.Network COM object to set the default printer. The comment block is longer than the script, but I think it’s a useful little tool.

Sets a Network Printer connection as the default printer.

Uses a COM object to sets the specified, installed printer as the default. If
an error is encountered, e.g., the specified printer isn't installed, the
exception is written to a file called Set-DefaultPrinter.err in the current
$env:temp directory, and then the script terminates, throwing the exception.

Based on my colleague's VBScript solution:

.PARAMETER PrinterShare
The UNC path to the shared printer.
e.g. \\\ETS-SAA-SamsungML-3560

Set-DefaultPrinter.ps1 -PrinterShare '\\\ETS-SAA-SamsungML-3560'

    Script Name: Set-DefaultPrinter.ps1
    Author     : Geoff Duke <>


        HelpMessage="Enter the UNC path to the network printer")]
    [string] $PrinterShare

Set-PSDebug -Strict

$PSDefaultParameterValues = @{"out-file:Encoding"="ASCII"}

$ws_net = New-Object -COM WScript.Network

try {
catch {
    $error[0].exception | out-file (join-path $env:temp 'Set-DefaultPrinter.err') 
    throw $error[0]
write-verbose "Default printer now $PrinterShare"

Leave a Reply