Monday, July 23, 2018

List Print Queues on Print Server with .NET for Performance in PowerShell

Using .NET to query print queues is much faster, here is the difference running the script on two print servers:

Print Queue CountWMI.NET
20210.77 seconds 0.475 seconds 
166796.87 seconds 3.2 seconds

WMI Script:

Measure-Command {
    Get-WMIObject -Class Win32_Printer | Select Name
}

.NET Script:

Measure-Command {
     Add-Type -AssemblyName System.Printing
    $PrintServer = New-Object System.Printing.PrintServer
    $PrintQueues =$PrintServer.GetPrintQueues()

    foreach ($Queue in $PrintQueues) {
        Write-Host ($Queue.Name)
    }
}

No comments:

Post a Comment

Compare Print Queues on Two Print Servers

In an active-active print servers scenario, we would like to make sure all print queues are identical. This means: 1. Print queue names are...