# Choice

### Prompt for choice

Sometimes in the interactive session when we are executing the scripts, and where it requires an input/consent from the user to proceed further we can prompt the user to choose from the given choices… # PromptForChoice Args $Title = &#34;Do you want to proceed further?&#34;$Prompt = &#34;Enter your choice&#34; $Choices = [System.Management.Automation.Host.ChoiceDescription[]] @(&#34;&amp;Yes&#34;, &#34;&amp;No&#34;, &#34;&amp;Cancel&#34;)$Default = 1 # Prompt for the choice $Choice =$host.UI.PromptForChoice($Title,$Prompt, $Choices,$Default) # Action based on the choice switch(\$Choice) { 0 { Write-Host &#34;Yes - Write your code&#34;} 1 { Write-Host &#34;No - Write your code&#34;} 2 { Write-Host &#34;Cancel - Write your code&#34;} }

15 January 2019