- using namespace System.Management.Automation.Host
- function New-Menu {
- [CmdletBinding()]
- param(
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [string]$Title,
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [string]$Question
- )
- $red = [ChoiceDescription]::new('&Red', 'Favorite color: Red')
- $blue = [ChoiceDescription]::new('&Blue', 'Favorite color: Blue')
- $yellow = [ChoiceDescription]::new('&Yellow', 'Favorite color: Yellow')
- $options = [ChoiceDescription[]]($red, $blue, $yellow)
- $result = $host.ui.PromptForChoice($Title, $Question, $options, 0)
- switch ($result) {
- 0 { 'Your favorite color is Red' }
- 1 { 'Your favorite color is Blue' }
- 2 { 'Your favorite color is Yellow' }
- }
- }
Raw Paste