🧬 WQL / PowerShell
Win32_Process: Sorting Processes (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_Process.
ProcessSorted.ps1
<#
.SYNOPSIS
WQL reference: sorting Processes results (Win32_Process).
.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
.\ProcessSorted.ps1
#>
[CmdletBinding()]
param()
$wqlQuery = "SELECT Name, ProcessId, WorkingSetSize, ThreadCount FROM Win32_Process"
Get-CimInstance -Query $wqlQuery |
Sort-Object -Property Name |
Format-Table -Property Name, ProcessId, WorkingSetSize, ThreadCount -AutoSize