Creating a Menu

rated by 0 users
Not Answered This post has 0 verified answers | 3 Replies | 3 Followers

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


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.

All Replies

Not Ranked
5 Posts

change this line

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


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


then amend the CASE senario to:

switch ($result)
        0 {
           "** Option A **";
        1 {
           "** Option B **";
        2 {
           "** Option C **";

Not Ranked
1 Posts

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?


Not Ranked
1 Posts

I know this is a little late, but for anyone else browsing the forum, take a look at my blog for an example on creating menus: 

I use functions to loop back around to my menu and find it a little easier than the do/switch method myself.

Page 1 of 1 (4 items) | RSS
Copyright 2012 All rights reserved.