Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<#
Set strict mode
#>
Set-StrictMode -Version 1.0
<#
Brian Schroer
Enum.GetValues and Enum.GetNames return arrays sorted by value
http://geekswithblogs.net/brians/archive/2007/12/18/117799.aspx
#>
enum FieldWidths
{
CustomerNumber = 5
OrderNumber = 10
City = 30
State = 2
Zip = 11
}
function listNames( [string[]] $list)
{
[int] $id=0;
[string] $formatLog = "{0}) {1}";
Write-Host "List Names"
Write-Host "***********"
$list | ForEach-Object{
$_obj = $_
$log = $formatLog -f `
($id +1) `
, $_obj `
;
Write-Host $log -ForegroundColor White;
$id = $id + 1;
}
}
function listValues( [int[]] $list)
{
[int] $id=0;
[string] $formatLog = "{0}) {1} {2}";
Write-Host "List Values"
Write-Host "***********"
$list | ForEach-Object{
$_obj = $_
$log = $formatLog -f `
($id +1) `
, $_obj `
, [int] $_obj `
;
Write-Host $log -ForegroundColor White;
$id = $id + 1;
}
}
[string[]] $listName = $null;
[int[]] $listValue = $null;
$listName = [System.Enum]::GetNames( `
'FieldWidths' `
);
$listValue = [System.Enum]::GetValues( `
'FieldWidths' `
);
Write-Host; Write-Host
listNames $listName
Write-Host; Write-Host
listValues $listValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.