Advertisement
Lee_Dailey

Simple text menu demo

Mar 21st, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $MenuItems = ('1 - First item',
  2.               '2 - Second choice',
  3.               '3 - Third selection',
  4.               'x - Exit')
  5. $ValidChoices = $MenuItems | ForEach-Object {$_[0]}
  6.  
  7. $Choice = ''
  8. while ($Choice -notin $ValidChoices)
  9.     {
  10.     Clear-Host
  11.     $MenuItems
  12.     Write-Output ''
  13.     $Choice = (Read-Host "Please enter a choice from the above items ").ToLower()
  14.     }
  15.  
  16. Write-Output ''
  17. switch ($Choice)
  18.     {
  19.     '1' {Write-Output "Do the first thing."; break}
  20.     '2' {Write-Output "The 2nd thing must be done."; break}
  21.     '3' {Write-Output "Three is the number of the thing to do."; break}
  22.     'x' {Write-Output "Exit now."; break}
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement