I’ve been running into this a lot lately and it’s really annoying because the “Doesn’t Work” entry below is always my first instinct on how to handle this…
$ht = @{Key1 = "Value1"; Key3 = "Value3"; Key2 = "Value2"} # Works... [pscustomobject]$ht # Works... [pscustomobject]@{Key1 = "Value1"; Key3 = "Value3"; Key2 = "Value2"} # Works... [pscustomobject][ordered]@{Key1 = "Value1"; Key3 = "Value3"; Key2 = "Value2"} # Doesn't Work... [pscustomobject][ordered]$ht
My current workaround (which really isn’t all that ugly, but still…
$SortedHashTable = $ht.GetEnumerator() | Sort-Object -Property Name [pscustomobject]$SortedHashTable
Anybody know why [pscustomobject][ordered]$ht doesn’t work?
submitted by /u/fourierswager
[link] [comments]
The post Regarding [pscustomobject] and [ordered] Type Accelerators: A mildly annoying scenario that I’ve encountered a lot recently appeared first on How to Code .NET.