PowerShell Multi-Key Stable Sort with Nulls Last
PowerShell
function Sort-Record {
param(
[Parameter(Mandatory)][object[]]$InputObject,
[string[]]$Property = @('Name'),
[switch]$Descending
)
$all = @($InputObject | Sort-Object -Stable -Property $Property -Descending:$Descending)
$key = $Property[0]
$withValue = @($all | Where-Object { $null -ne $_.$key })
$nullRows = @($all | Where-Object { $null -eq $_.$key })
$withValue + $nullRows # null keys always sink to the end
}