• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1507
  • Last Modified:

Display System.Management.Automation.Host.ChoiceDescription as a list?

If I have the code as shown below, I get the output as shown in the attached picture. How do I get the options to display in a list mode that looks like the following?

[A] Option A
[B] Option B
[C] Option C
# Clears the Screen
# Define Main Level Title and Message Variables
$main_title = "PowerShell Network Management Console v1.0"
$main_message = "What management tasks would you like to perform?"
# Define Main Level Menu Options
$main_activedirectory = New-Object System.Management.Automation.Host.ChoiceDescription "&Active Directory Related", "Performs tasks related to Active Directory management."
$main_computer = New-Object System.Management.Automation.Host.ChoiceDescription "&Computer Related", "Performs tasks on and retrieves information from the specified computer or computers."
$main_exchange = New-Object System.Management.Automation.Host.ChoiceDescription "&Exchange Related", "Performs tasks related to Exchange management."
$main_quit = New-Object System.Management.Automation.Host.ChoiceDescription "&Quit", "Quits the PowerShell Network Management Console."
# Display Main Level Menu Options
$main_options = [System.Management.Automation.Host.ChoiceDescription[]] ($main_activedirectory, $main_computer, $main_exchange, $main_quit)
# Prompt for Main Level Menu Choice
$main_result = $Host.UI.PromptForChoice($main_title, $main_message, $main_options, 3)
# Handle Main Level Menu Choices
switch ($main_result)
		0 {ActiveDirectory_Menu}
		1 {Computer_Menu}
		2 {Exchange_Menu}
		3 {Quit_Menu}

Open in new window

1 Solution
dfxdeimosAuthor Commented:
Figured it out, I had to do something like what you see in the code example.
# Prompt for Main Level Menu Choice
$Main_Prompt = '
[1] Active Directory Menu
[2] Computer Menu
[3] Exchange Menu
[4] Quit
# Handle Main Level Menu Choices
switch (Read-Host $Main_Prompt)
		1 {ActiveDirectory_Menu}
		2 {Computer_Menu}
		3 {Exchange_Menu}
		4 {Quit_Menu}

Open in new window


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now