What's wrong with '$result = $host.ui.PromptForChoice($title, $message, $options, 0) - IN VISUAL STUDIO CODE (Powershell)

Henning Reckey 1 Reputation point
2022-06-27T12:14:45.527+00:00

Hi there

I'm trying to change from Powershell ISE to visual studio code(Powershell) and all looks pretty good (80%). I have quite a few 'menu systems' in Powershell which I do not get the same pleasure off seeing in VS code. I don't get the 'pop-up' menu, so now I hope you can tell me which 'extension' that might be missing or 'that's not possible'. You have earlier been looking at something similar:

https://learn.microsoft.com/en-us/answers/questions/765611/three-choices-prompt-in-powershell.html

Regards

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,629 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,596 Reputation points
    2022-06-27T14:53:28.667+00:00

    The difference is the host that run PowerShell. In one case it's ISE, in the other it's VS Code. How prompts are handled depends on the host, not PowerShell.

    The ISE prefers to display a dialog box (not a menu!). VS Code uses something closer to what happens when the host is Powershell (a textual shell) and not ISE which is a graphic shell)

    0 comments No comments

  2. Limitless Technology 39,811 Reputation points
    2022-06-28T15:48:20.857+00:00

    Hi Henning,

    Thanks for posting the query and we are happy to help you regarding running PowerShell from Visual studio.

    In PowerShell you have used .NET System.Management.Automation.Host.ChoiceDescription object.

    This object allows to define different options and then use a .NET method called PromptForChoice() to display those options to the user.

    Usually the dialogue box or prompt window will be rendered based on the framework or ISE we are using.

    You can try installing respective modules searching from NuGet packages for PowerShell.

    https://learn.microsoft.com/en-us/nuget/reference/ps-reference/ps-ref-install-package

    For better understanding of using PowerShell in DotNet code, kindly refer following links.

    https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/vscode/using-vscode?view=powershell-7.2

    https://devblogs.microsoft.com/scripting/visual-studio-code-editing-features-for-powershell-development-part-1/

    https://devblogs.microsoft.com/scripting/visual-studio-code-editing-features-for-powershell-development-part-2/

    Here is a helpful page with information about Windows PowerShell

    https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/powershell

    -----------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer.--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.