Listing enumeration type values (updated)
The old function return duplicate names when the enumeration has two names with the same value, for example:
PS > Get-EnumValues Microsoft.PowerShell.ExecutionPolicy
Name Value
---- -----
Unrestricted 0
RemoteSigned 1
AllSigned 2
Restricted 3
Restricted 3
Here is the modified version of the function:
function Get-EnumValues([type]$type){
[enum]::getNames($type) | select @{n="Name";e={$_}},@{n="Value";e={$type::$_.value__}} | ft -auto
}
And the results:
PS > Get-EnumValues Microsoft.PowerShell.ExecutionPolicy Name Value ---- ----- Unrestricted 0 RemoteSigned 1 AllSigned 2 Restricted 3 Default 3
-Shay



1 comment:
Awesome. Thanks for sharing it!
Post a Comment