Using .NET to query print queues is much faster, here is the difference running the script on two print servers:
Print Queue Count | WMI | .NET |
202 | 10.77 seconds | 0.475 seconds |
1667 | 96.87 seconds | 3.2 seconds |
WMI Script:
Measure-Command {
Get-WMIObject -Class Win32_Printer | Select Name
}
.NET Script:
.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