🧬 WQL / PowerShell
Win32_Printer: Sorting Printers (WQL has no ORDER BY)
WQL has no ORDER BY clause — this shows the standard workaround of piping Get-CimInstance results through Sort-Object on Win32_Printer.
PrinterSorted.ps1
<#
.SYNOPSIS
WQL reference: sorting Printers results (Win32_Printer).
.DESCRIPTION
WQL (the WMI Query Language) does not support an ORDER BY clause —
unlike regular SQL. Sort after the fact with Sort-Object instead;
this is one of the most common WQL gotchas for people coming from
SQL backgrounds.
.EXAMPLE
.\PrinterSorted.ps1
#>
[CmdletBinding()]
param()
$wqlQuery = "SELECT Name, DriverName, PortName, PrinterStatus FROM Win32_Printer"
Get-CimInstance -Query $wqlQuery |
Sort-Object -Property Name |
Format-Table -Property Name, DriverName, PortName, PrinterStatus -AutoSize