🧬 WQL / PowerShell

Win32_SystemDriver: Sorting System Drivers (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_SystemDriver.

By WindowsScripting.com · 623 B
SystemDriverSorted.ps1
<#
.SYNOPSIS
    WQL reference: sorting System Drivers results (Win32_SystemDriver).

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

[CmdletBinding()]
param()

$wqlQuery = "SELECT Name, DisplayName, State, PathName FROM Win32_SystemDriver"

Get-CimInstance -Query $wqlQuery |
    Sort-Object -Property Name |
    Format-Table -Property Name, DisplayName, State, PathName -AutoSize