Skip to main content

Retrieve Printer Queue Statistics

Problem

You want to get information about print queues for printers on the current system.

Solution

To retrieve information about printers attached to the system, use the Win32_ PerfFormattedData_Spooler_PrintQueue WMI class:

PS >GetWmiObject Win32_PerfFormattedData_Spooler_PrintQueue | >> Select Name,TotalJobsPrinted >>

Name TotalJobsPrinted

Microsoft Office Document Image Wr...

0 Microsoft Office Document Image Wr...

0 CutePDF Writer

0 Brother DCP1000

2 _Total

2

To retrieve information about a specific printer, apply a filter based on its name, as shown in Example 244.

Example 244. Retrieving information about a specific printer

PS >$queueClass = "Win32_PerfFormattedData_Spooler_PrintQueue" PS >$filter = "Name='Brother DCP1000'" PS >$stats = GetWmiObject $queueClass Filter $filter PS >$stats | FormatList *

AddNetworkPrinterCalls : 129 BytesPrintedPersec : 0 Caption : Description : EnumerateNetworkPrinterCalls : 0 Frequency_Object : Frequency_PerfTime : Frequency_Sys100NS : JobErrors : 0 Jobs : 0 JobsSpooling : 0 MaxJobsSpooling : 1 MaxReferences : 3 Name : Brother DCP1000 NotReadyErrors : 0 OutofPaperErrors : 0 References : 2 Timestamp_Object : Timestamp_PerfTime : Timestamp_Sys100NS : TotalJobsPrinted : 2 TotalPagesPrinted : 0

To retrieve specific properties, access as you would access properties on other PowerShell objects:

PS >$stats.TotalJobsPrinted

Discussion

The Win32_PerfFormattedData_Spooler_PrintQueue WMI class provides access to the various Windows performance counters associated with print queues. Because of this, you can also access them through the .NET Framework.

$printer = "Brother DCP1000" $pc = NewObject Diagnostics.PerformanceCounter "Print Queue","Jobs",$printer $pc.NextValue()

If you need dedicated infrastructure for Windows workloads, consider a USA Dedicated Server for greater control over PowerShell automation, system monitoring, service management, and server resources.

Help Category