Private/MenuUtil.ps1
function Show-Menu { param ( [Parameter(Mandatory=$true)] [string]$Title, [Parameter(Mandatory=$true)] [string[]]$Choices ) Write-Host "" Write-Host "===== $Title =====" Write-Host "" $number = 0 foreach ($choice in $Choices) { $number++ Write-Host "[$number] $choice" } Write-Host "" do { $selection = Read-Host "Please make a selection" } until ($selection -match "^[\d]+$" -and $selection -ge 1 -and $selection -le $Choices.Count) $selected = $Choices[$selection-1] Write-Host "You've selected [$selection], $selected" return $selection-1 } |