2

When I did $name = Read-Host 'What is your name?' in Powershell V1 it would ask the question in a pop-up window.

With Powershell V3 it just asks in the console window. Is there a way to force Read-Host questions to pop-up still?

jscott
  • 24,484
  • 8
  • 79
  • 100
finisterre
  • 305
  • 1
  • 3
  • 11

1 Answers1

2

There are lots of ways to skin this cat. Here is one:

[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')    
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your name", "Name", "$env:username")

And with the [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") and [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") assemblies, you can make a full-featured, customized input box just like you would with C#.

Ryan Ries
  • 55,481
  • 10
  • 142
  • 199
  • Cool. Thanks. I'm VB.Net more than C#. Do you know any good sites or books I can read about this stuff? I like the idea of a proper graphical GUI with drop-downs, check-boxes etc. – finisterre Mar 25 '13 at 17:04
  • Yeah, check out what this guy does with System.Drawing and System.Windows.Forms assemblies. You can add all the buttons and drop-downs and controls you can imagine: http://powershell-tips.blogspot.com/2012/10/display-inputbox-with-powershell_23.html – Ryan Ries Mar 25 '13 at 17:05
  • One thing with this. The pop-ups are popping out behind my main PowerShell window. Any way of making them appear in the foreground? – finisterre Mar 26 '13 at 13:32
  • http://stackoverflow.com/questions/9978727/focus-window-created-by-powershell-script – Ryan Ries Mar 26 '13 at 13:43