Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1076719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:28:15+00:00 2026-05-16T21:28:15+00:00

I don’t remember ever being prompted for multiple selections before in PowerShell, but I’ve

  • 0

I don’t remember ever being prompted for multiple selections before in PowerShell, but I’ve seen several examples of hosts implementing this interface. Unfortunately, those are the only references I’ve seen to the interface. I’ve never seen “here’s how to test that you’re implementing it correctly”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:28:16+00:00Added an answer on May 16, 2026 at 9:28 pm

    Please, disregard my first answer; it is not an answer at all, as I can see now. And thank you for a really interesting question.

    I still do not know cmdlets that use that interface. But we can use it on our own from scripts. Let’s modify the mentioned Get-Choice.ps1 and call the new one Get-Choice2.ps1:

    <#
    .SYNOPSIS
        Displays PowerShell style menu and gets user choices
    
    .DESCRIPTION
        *) Returns choice indexes.
        *) Choice keys are indicated by '&' in menu items.
        *) Help strings can be empty or nulls (items are used themselves).
    #>
    
    param
    (
        # Menu caption
        [string]$Caption = 'Confirm',
        # Menu message
        [string]$Message = 'Are you sure you want to continue?',
        # Choice info pairs: item1, help1, item2, help2, ...
        [string[]]$Choices = ('&Yes', 'Continue', '&No', 'Stop'),
        # Default choice indexes (i.e. selected on [Enter])
        [int[]]$DefaultChoice = @(0)
    )
    if ($args) { throw "Unknown parameters: $args" }
    if ($Choices.Count % 2) { throw "Choice count must be even." }
    
    $descriptions = @()
    for($i = 0; $i -lt $Choices.Count; $i += 2) {
        $c = [System.Management.Automation.Host.ChoiceDescription]$Choices[$i]
        $c.HelpMessage = $Choices[$i + 1]
        if (!$c.HelpMessage) {
            $c.HelpMessage = $Choices[$i].Replace('&', '')
        }
        $descriptions += $c
    }
    
    $Host.UI.PromptForChoice($Caption, $Message, [System.Management.Automation.Host.ChoiceDescription[]]$descriptions, $DefaultChoice)
    

    Now we test it:

    Get-Choice2 'Title' 'Message' -DefaultChoice 0, 1, 2 -Choices @(
        'Choice &1', 'This is choice 1'
        'Choice &2', ''
        'Choice &3', ''
        'Choice &4', ''
        'Choice &5', ''
        'Choice &6', ''
        'Choice &7', ''
        'Choice &8', ''
        'Choice &9', ''
        'Choice &0', ''
    )
    

    It prints 10 choices, the first 3 are highlighted (in the console host), and prompts:

    0> Test-Get-Choice2.ps1
    Title
    Message
    [1] Choice 1
    [2] Choice 2
    [3] Choice 3
    [4] Choice 4
    [5] Choice 5
    [6] Choice 6
    [7] Choice 7
    [8] Choice 8
    [9] Choice 9
    [0] Choice 0
    [?] Help
    (default choices are 1,2,3)
    Choice[0]:
    

    If we press Enter immediately the output is the default 3 indexes: 0, 1, 2. If we type, for example: 5 + Enter + 3 + Enter + 1 + Enter + Enter then the output is 4, 2, 0.

    It works. PowerShell ISE also supports this but the UI might be something better in GUI version, perhaps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know if this has been asked before, but what i'd like to
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
Don't ask me why but I need to do the following: string ClassName =
I don't know why, but this code worked for me a month ago... maybe
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.