🧬 WQL / PowerShell
Win32_Group: Sorting Local Groups (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_Group.
GroupSorted.ps1
<#
.SYNOPSIS
WQL reference: sorting Local Groups results (Win32_Group).
.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
.\GroupSorted.ps1
#>
[CmdletBinding()]
param()
$wqlQuery = "SELECT Name, Description, Domain FROM Win32_Group"
Get-CimInstance -Query $wqlQuery |
Sort-Object -Property Name |
Format-Table -Property Name, Description, Domain -AutoSize