PowerShell Printer Scripts

PowerShell Printers

I will show you how to use PowerShell to extract information about your printers. We will create a script which not only lists the printers, but also reveals their properties. For example, the printer’s sharename, driver, status and 90 other properties.

Despite being one of the first devices to be ‘plug and play’, printers still give more than their fair share of problems. One clue of trouble ahead is the large number of adjectives to qualify the context of the word printer, for example, driver, device, default, network and share. All this means is that printers provide rich pickings for writing good PowerShell cmdlets. Here are possible tasks for a printer script:

Many of these printer cmdlets employ WMI to interrogate computer objects such as printers. As you may know, Get-WmiObject opens up a whole world of system objects, which you can then use PowerShell to read their values.

The point of this initial research is to answer the question, ‘How did Guy know to use the class Win32_Printer?’

Learning Points

Note 4: FT means: Format-Table with the following properties. Incidentally, you could append -auto.

Guy Recommends: Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Note 10: You must edit the value for $PrinterPath to reflect a computer on your network.

Note 11: This PowerShell script does not use WmiObject with its Win32 class, but instead it uses:New-Object -Com WScript.Network.

Note 12: Troubleshooting There should be no space before the bracket, this mistake caused me some head-scratching, until I realized that for once there was no spelling mistake in AddWindowsPrinterConnection, just an unwanted space:$net.AddWindowsPrinterConnection ($PrinterPath)

Summary of PowerShell Printer Scripts

Ever since I can remember, printers give more problems than any other hardware. PowerShell is not the magic bullet to cure all your printer problems, however, PowerShell makes it easier to configure printers than using the same commands in VBScript.