🧬 WQL / PowerShell
Win32_Service: Sorting Services (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_Service.
ServiceSorted.ps1
<#
.SYNOPSIS
WQL reference: sorting Services results (Win32_Service).
.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
.\ServiceSorted.ps1
#>
[CmdletBinding()]
param()
$wqlQuery = "SELECT Name, DisplayName, State, StartMode, Status FROM Win32_Service"
Get-CimInstance -Query $wqlQuery |
Sort-Object -Property Name |
Format-Table -Property Name, DisplayName, State, StartMode, Status -AutoSize