Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Regarding [pscustomobject] and [ordered] Type Accelerators: A mildly annoying scenario that I’ve encountered a lot recently

$
0
0

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.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images