none
How to use user input from a menu to run cmdlets in PowerShell RRS feed

  • General discussion

  • Hello,

    I am a student new to PowerShell and I am having a difficult time trying to find the best way to get the user input from my menu to run cmdlets and show output on the screen. I am lost as to how I can get the user input to run specific cmdlets or functions and put those together for this program. Any advice or links to training for this would be greatly appreciated.

    function Show-Menu #This code is used to create a menu of choices for the user.
    {
         param (
               [string]$Title = 'My Menu'
         )
         cls
         Write-Host "================Sean'sProgram ================"
         
         Write-Host "1: Press '1' To Show Computer Name."
         Write-Host "2: Press '2' To Get IP Address Info."
         Write-Host "3: Press '3' To Show DNS Info."
         Write-Host "4: Press '4' To Show Default Gateway."
         Write-Host "5: Press '5' To Show Memory."
         Write-Host "6: Press '6' To Show ENV Variable Path."
         Write-Host "7: Press '7' To Show Drivers."
         Write-Host "8: Press '8' To Show Tasks Running."
         Write-Host "9: Press '9' To stop Process."
         Write-Host "10: Press '10' To Show File Security Info."
         Write-Host "11: Press '11' To Show TCP Connections and Ports."
         Write-Host "Q: Press 'Q' to quit."
    }

    do
    {
         Show-Menu
         $input = Read-Host "Please make a selection"
         switch ($input)
         {
               '1' { 
                    cls
                    'You chose option #1'
               } '2' {
                    cls
                    'You chose option #2'
               } '3' {
                    cls
                    'You chose option #3'
               } 'q' {
                    return
               }
         }
         pause
    }
    until ($input -eq 'q')


    • Changed type Bill_Stewart Monday, December 17, 2018 6:06 PM
    • Moved by Bill_Stewart Monday, December 17, 2018 6:06 PM This is not "someone do my homework for me" forum
    Thursday, September 27, 2018 2:02 PM

All replies