🧬 WQL / PowerShell

Win32_BaseBoard: Sorting Motherboard 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_BaseBoard.

By WindowsScripting.com · 626 B
BaseBoardSorted.ps1
<#
.SYNOPSIS
    WQL reference: sorting Motherboard Info results (Win32_BaseBoard).

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

[CmdletBinding()]
param()

$wqlQuery = "SELECT Manufacturer, Product, SerialNumber FROM Win32_BaseBoard"

Get-CimInstance -Query $wqlQuery |
    Sort-Object -Property Manufacturer |
    Format-Table -Property Manufacturer, Product, SerialNumber -AutoSize