# Prompt for choice in PowerShell

> Source: <https://gist.github.com/kpatnayakuni/da1c1d6e4d9b6e457727a9394af5170d>
> Published: 2019-01-15 16:33:59+00:00

Demo-Choices.ps1

      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      
Learn more about bidirectional Unicode characters

 
    Show hidden characters

# PromptForChoice Args

$Title = "Do you want to proceed further?"

$Prompt = "Enter your choice"

$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No", "&Cancel")

$Default = 1

# Prompt for the choice

$Choice = $host.UI.PromptForChoice($Title, $Prompt, $Choices, $Default)

# Action based on the choice

switch($Choice)

{

    0 { Write-Host "Yes - Write your code"}

    1 { Write-Host "No - Write your code"}

    2 { Write-Host "Cancel - Write your code"}

}
