title: User selection menu from a PowerShell array with more than 9 items
body: <p>I have a PowerShell function that I use to generate interactive menus on the fly. I pass values to an array name $mlist and then generate the menu based on the contents of the array. The user simply selects the number associated with their desired choice. The code works fine when the array contains 9 items or less. If the array contains more than 9 items, the only selection I can choose is "1". Choosing any other selection results in the menu being displayed again. I have it encapsulated in a while statement and this is the desired function when no item is selected. So basically it ignores any entry other than "1" when the array contains more than 9 items. Here is the code:</p>
  
  <pre><code>$global:ans = $null
  $global:selection = $null
  While ($ans -lt 1 -or $ans -gt $mlist.count){
      $mhead
      Write-Host # empty line
      $menu = @{}
      for ($i=1;$i -le $mlist.count;$i++) {
          if ($mlist.count -gt 1){
              Write-Host -fore Cyan "  $i." $($mlist[$i-1]) 
              $menu.Add($i,($mlist[$i-1]))
          }else{
              Write-Host -fore Cyan "  $i." $mlist
              $menu.Add($i,$mlist)
          }
      }
      Write-Host # empty line
      $global:ans = Read-Host 'Please enter selection'
  }
  $global:selection = $menu.Item([int]$ans)
  </code></pre>