function Get-Choice ([array] $Items) { Set-StrictMode -Version Latest do { $Items | ForEach-Object { $i = 0 } { '{0,3}. {1}' -f (++$i),$_ } $choice = Read-Host Your choice } while ($choice -notmatch '^\d+$' -or !(1..$Items.Length -eq $choice)) $Items[$choice-1] }