Last active
March 14, 2024 22:37
-
-
Save kpatnayakuni/da1c1d6e4d9b6e457727a9394af5170d to your computer and use it in GitHub Desktop.
Prompt for choice in PowerShell
This file contains 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
# 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"} | |
} |
Thank you!
Needed this, thanks!
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
Super, this was the solution I was looking for: an analog solution to the choice function in batches (.BAT)