{"slug": "prompt-for-choice-in-powershell", "title": "Prompt for choice in PowerShell", "summary": "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.", "body_md": "Demo-Choices.ps1\n\n      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.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\n# PromptForChoice Args\n\n$Title = \"Do you want to proceed further?\"\n\n$Prompt = \"Enter your choice\"\n\n$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @(\"&Yes\", \"&No\", \"&Cancel\")\n\n$Default = 1\n\n# Prompt for the choice\n\n$Choice = $host.UI.PromptForChoice($Title, $Prompt, $Choices, $Default)\n\n# Action based on the choice\n\nswitch($Choice)\n\n{\n\n    0 { Write-Host \"Yes - Write your code\"}\n\n    1 { Write-Host \"No - Write your code\"}\n\n    2 { Write-Host \"Cancel - Write your code\"}\n\n}", "url": "https://wpnews.pro/news/prompt-for-choice-in-powershell", "canonical_source": "https://gist.github.com/kpatnayakuni/da1c1d6e4d9b6e457727a9394af5170d", "published_at": "2019-01-15 16:33:59+00:00", "updated_at": "2026-05-24 03:33:52.847343+00:00", "lang": "en", "topics": ["developer-tools"], "entities": [], "alternates": {"html": "https://wpnews.pro/news/prompt-for-choice-in-powershell", "markdown": "https://wpnews.pro/news/prompt-for-choice-in-powershell.md", "text": "https://wpnews.pro/news/prompt-for-choice-in-powershell.txt", "jsonld": "https://wpnews.pro/news/prompt-for-choice-in-powershell.jsonld"}}