🧬 WQL / PowerShell

Win32_QuickFixEngineering: Sorting Installed Hotfixes (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_QuickFixEngineering.

By WindowsScripting.com · 678 B
QuickFixEngineeringSorted.ps1
<#
.SYNOPSIS
    WQL reference: sorting Installed Hotfixes results (Win32_QuickFixEngineering).

.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
    .\QuickFixEngineeringSorted.ps1
#>

[CmdletBinding()]
param()

$wqlQuery = "SELECT HotFixID, Description, InstalledOn, InstalledBy FROM Win32_QuickFixEngineering"

Get-CimInstance -Query $wqlQuery |
    Sort-Object -Property HotFixID |
    Format-Table -Property HotFixID, Description, InstalledOn, InstalledBy -AutoSize