INTRODUCTION

In this blog post I will 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 two if you have the need to.

SOLUTION

$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"}     
} 

REFERENCES

RELATED POSTS