Installing Local Printer

by Feb 8, 2013

WMI represents all locally installed printers with its class Win32_Printer, so you can easily look what's installed:

PS> Get-WmiObject -Class Win32_Printer | Select-Object -Property *

To add a new local printer, just add a new instance of Win32_Printer. The example adds a new local printer and shares it over the network (provided you have sufficient privileges and the appropriate printer drivers):

$printerclass = [wmiclass]'Win32_Printer'
$printer = $printerclass.CreateInstance()
$printer.Name = $printer.DeviceID = 'NewPrinter'
$printer.PortName = 'LPT1:'
$printer.Network = $false
$printer.Shared = $true
$printer.ShareName = 'NewPrintServer'
$printer.Location = 'Office 12'
$printer.DriverName = 'HP LaserJet 3050 PCL5'
$printer.Put() 

To find out what the properties are that you must set for a given printer, simply install the printer manually on a test system, then query the installed printer with the line above.

This will dump all the properties like driver name etc. that you need to set to install the printer via script.

Twitter This Tip! ReTweet this Tip!