Skip to content

Instantly share code, notes, and snippets.

@kpatnayakuni
Last active March 14, 2024 22:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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"}
}
@mchwalt
Copy link

mchwalt commented Aug 4, 2023

Super, this was the solution I was looking for: an analog solution to the choice function in batches (.BAT)

Copy link

ghost commented Aug 31, 2023

Thank you!

@DylDevs
Copy link

DylDevs commented Jan 16, 2024

Needed this, thanks!

@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