Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell menu selection (like GRUB, curses, etc.) [closed]

I want do provide the user with a menu in Powershell where he can select entities with the arrow keys just like in GRUB or just the very basic idea of curses to replace the (Y)es or (N)o command line inputs. (Or for folder selection or whatever)

Is there already a framework or something that can help me as a starting point?

I already checked the Out-GridView, but this leaves Powershell to another window.

like image 440
Kaffeepause Avatar asked Jul 10 '13 16:07

Kaffeepause


People also ask

How do you exit a PowerShell script?

Open a PowerShell console session, type exit , and press the Enter key. The PowerShell console will immediately close. This keyword can also exit a script rather than the console session.

How do you do a while loop in PowerShell?

PowerShell While loop As long as the condition is true, PowerShell will execute the script block until the condition results in false. Write-Host End of While loop. $var = 1 while ($var -le 5) { Write-Host The value of Var is: $var $var++ } Write-Host End of While loop.


1 Answers

You need to use the System.Management.Automation.Host.ChoiceDescription .NET Framework class, which is designed for console menus.

For a very good example of use, see this Technet Blog article.

EDIT: I missed the fact that you wanted an arrow keys/enter key driven CLI menu.

I found a blog post from Jakob Bindslet that seems to be just what you wanted, although I confess I can't try it just yet, but I can't wait to!

EDIT: Another excellent option from Micahel Albert can be found on his blog; I found this option to be superior in that it does not clear the console window on arrow navigation.

like image 111
Graham Gold Avatar answered Oct 22 '22 07:10

Graham Gold