Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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#.

share|improve this answer
    
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: powershell-tips.blogspot.com/2012/10/… –  Ryan Ries Mar 25 '13 at 17:05
    
Thanks. Will do. –  finisterre Mar 25 '13 at 17:22
    
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
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.