Add network printer with PowerShell

This is my PowerShwell translation of my colleague’s VBScript solution for mapping network printers with a script.

Add a Network Printer connection, optionally making it the default printer.

Uses a COM object to add a Network Printer, and optionally sets that printer
as the default. If an error is encountered, the exception is written to a
file called Add-NetworkPrinter.err in the current $env:temp directory, and then
the script terminates.

This is my PowerShell translation of my colleague's VBScript solution:

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

Specifies that the printer will also be set as the default printer for the current user.

Add-NetworkPrinter.ps1 -PrinterShare '\\\ETS-SAA-SamsungML-3560' -Default

    Script Name: Add-NetworkPrinter.ps1
    Author     : Geoff Duke <>


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

    [switch] $Default

Set-PSDebug -Strict

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

$ws_net = New-Object -COM WScript.Network

write-verbose "Adding connection to $PrinterShare"
try {
catch {
    $error[0].exception | out-file (join-path $env:temp 'Add-NetworkPrinter.err')
    throw $error[0]

write-verbose "Setting the printer as the default"
if ( $Default ) {
    try {
    catch {
        $error[0].exception | out-file (join-path $env:temp 'Add-NetworkPrinter.err')
        throw $error[0]

# the end

For use with Group Policy, it will probably be helpful to create a simple Set-DefaultPrinter.ps1 script. But that’s just the second stanza from the script above.

2 thoughts on “Add network printer with PowerShell

  1. Pingback: Set default printer with PowerShell | Geoff @ UVM

  2. Pingback: Addnetwork Printer | wiki - pro printing services

Leave a Reply