cd /news/developer-tools/prompt-for-choice-in-powershell · home topics developer-tools article
[ARTICLE · art-13054] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Prompt for choice in PowerShell

The article provides a PowerShell script example demonstrating how to use the `$host.UI.PromptForChoice` method to present a user with three options: "Yes", "No", and "Cancel". It sets a title, prompt text, and a default selection, then uses a switch statement to execute different code blocks based on the user's choice.

read1 min views23 publishedJan 15, 2019

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
$Title = "Do you want to proceed further?"

$Prompt = "Enter your choice"

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

$Default = 1


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


switch($Choice)

{

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

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

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

}
── more in #developer-tools 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/prompt-for-choice-in…] indexed:0 read:1min 2019-01-15 ·