Introduction

In this blog post, I provide a Powershell menu choice script for adding functionality to your scripts.

If you are creating a script and want the user to be able to select between different choices, you can either have a pop-up or use a menu selection in the console.

I prefer a menu selection in the console.

You can add more choices than the two in my example if you have the need to.

The Powershell menu script

Below is the Powershell code:

$Title = "Select OS" 
$Message = "What OS is your favorite?" 
$WindowsME = New-Object System.Management.Automation.Host.ChoiceDescription "&Windows ME", `     "Windows ME" 
$MacOSX = New-Object System.Management.Automation.Host.ChoiceDescription "&MacOSX", `     "MacOSX" 
$Options = [System.Management.Automation.Host.ChoiceDescription[]]($WindowsME, $MacOSX) 
$SelectOS = $host.ui.PromptForChoice($title, $message, $options, 0)      
switch($SelectOS) {         
    0 {Write-Host "You love Windows ME!"}         1 
    {Write-Host "You must be an Apple fan boy"}     
} 
Create a menu selection script in Powershell

Conclusion

Creating a Powershell menu script can be useful in many cases!

How have you created Powershell menus? Please leave a comment below!

Related posts

1 COMMENT

  1. awesome script. however, I added some options and for a couple of my menu options it puts them on the same line.

    Is there any way to add line breaks between menu choices? Thanks in advance.

LEAVE A REPLY

Please enter your comment!
Please enter your name here