🧬 WQL / PowerShell

Win32_Processor: Sorting Processor Info (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_Processor.

By WindowsScripting.com · 668 B
ProcessorSorted.ps1
<#
.SYNOPSIS
    WQL reference: sorting Processor Info results (Win32_Processor).

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

[CmdletBinding()]
param()

$wqlQuery = "SELECT Name, NumberOfCores, NumberOfLogicalProcessors, MaxClockSpeed FROM Win32_Processor"

Get-CimInstance -Query $wqlQuery |
    Sort-Object -Property Name |
    Format-Table -Property Name, NumberOfCores, NumberOfLogicalProcessors, MaxClockSpeed -AutoSize