Skip to content

Instantly share code, notes, and snippets.

@kpatnayakuni
Last active March 14, 2024 22:37
Show Gist options
  • Save kpatnayakuni/da1c1d6e4d9b6e457727a9394af5170d to your computer and use it in GitHub Desktop.
Save kpatnayakuni/da1c1d6e4d9b6e457727a9394af5170d to your computer and use it in GitHub Desktop.
Prompt for choice in PowerShell
# 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"}
}
@Abnrangerx67
Copy link

This is awesome, but is there a way to make the buttons stack? I have about six choices I want to use and right now with fours the gui is pretty long across.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment