-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-SingleOption.ps1
More file actions
32 lines (29 loc) · 1.12 KB
/
Get-SingleOption.ps1
File metadata and controls
32 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function Get-SingleOption {
[CmdletBinding()]
Param (
[parameter(Mandatory = $false)]
[string]$value = $(Throw ((Get-ResStr 'PARAM_MANDATORY_MISSED') -f 'value', $myInvocation.Mycommand))
,
[parameter(Mandatory = $false)]
[string[]]$list = $(Throw ((Get-ResStr 'PARAM_MANDATORY_MISSED') -f 'list', $myInvocation.Mycommand))
)
begin {
Write-Verbose -Message ((Get-ResStr 'STARTING_FUNCTION') -f $myInvocation.Mycommand)
New-Variable -Name 'idx' -Scope 'Private' -Value ([int32]0)
New-Variable -Name 'result' -Scope 'Private' -Value ([string]'')
$initialVariables = Get-CurrentVariables -Debug:$DebugPreference
}
process {
[int]$idx = $list.ToUpper().IndexOf($value.ToUpper())
if ($idx -eq -1) {
[string]$result = $list[0]
} else {
[string]$result = $list[$idx]
}
}
end {
Get-CurrentVariables -InitialVariables $initialVariables -Debug:$DebugPreference
Return $result
}
# Test: Get-SingleOption -value 'alpha' -list @('default','bravo','charlie','delta','echo')
}