Creating a Menu

rated by 0 users
This post has 2 Replies | 2 Followers

Not Ranked
Posts 1
pukenx Posted: 04-18-2012 8:56 PM

Hello,

I am in school and am looking for some help.  This is my assignment:

Unit 2 Lab Assignment 2

For this assignment, you will create a script that meets the following requirements:

  • Includes appropriate comments (see Role of Comments which is also located in the Course Materials and Resources in your Moodle course).

  • Clears the screen

  • Creates the menu displayed below with any additional formatting you may desire
  • menu
  • Prompts the user to choose a menu option

  • Assigns the value chosen by the user to the variable $choice

  • Prints "You chose option X" to the screen. Where X is the actual key that they pressed.

  • Requirements for "Show Services" menu item
    • Displays services sorted by status
    • Creates a csv file named services.csv with the same content and the data displayed on screen

  • Requirements for "Show Processes" menu item
    • Displays Process name and amount of Virtual Memory used
    • Display is sorted by amount of Virtual memory
    • The output is displayed in a web browser
    • Name the web page file processes.htm

  • Requirements for the "Show System Information" menu item
    • Displays output from systeminfo.ps1 script

  • Save the script as menu.ps1

This is the code I have so far:

$title = "System Utilities"
$message = "Select which utility you would like to view."

$A = New-Object System.Management.Automation.Host.ChoiceDescription "&A", ` "Show Services."

$B = New-Object System.Management.Automation.Host.ChoiceDescription "&B", ` "Show Processes."

$C = New-Object System.Management.Automation.Host.ChoiceDescription "&C", ' "Displays systeminfo.ps1"

$options = [New-Object System.Management.Automation.Host.ChoiceDescription[]] ($A, $B, $C)

$result = $host.ui.PromptForChoice($title, $message, $options, 0)

switch ($result)
    {
        0 {"You selected A." Get-Service}
        1 {"You selected B." Get-Process}
 2 {"You selected C." h:\ist321\systeminfo.ps1}
    }

I am getting an error message that says .\menu is not a recognized cmdlet.....

I am not expecting y'all to do my homework but my teacher is not helping with this.  Any help would be greatly appreciated.

Not Ranked
Posts 5

change this line

$options = [New-Object System.Management.Automation.Host.ChoiceDescription[]] ($A, $B, $C)

to

$options = [System.Management.Automation.Host.ChoiceDescription[]]($A, $B, $C)

 

then amend the CASE senario to:

switch ($result)
    {
        0 {
           "** Option A **";
           Get-Service
          }
        1 {
           "** Option B **";
           Get-Process
           }
        2 {
           "** Option C **";
            }
    }
     

Not Ranked
Posts 1

This works great from ISE but is there any way to have the user menus look just as good when the script is being called from a desktop shortcut?

 

Page 1 of 1 (3 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.