3

I've found this code to create simple input box for powershell:

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$title = 'Demographics'
$msg   = 'Enter your demographics:'

$text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

Does anyone know how to add more input fields?

1
  • I'd says use Windows Forms or WPF to make a real window with what you need in it, but maybe that's overkill. Commented May 31, 2016 at 21:01

1 Answer 1

6

WPF, XAML, .NET, and ShowUI are all options available to you.

https://learn-powershell.net/2012/09/13/powershell-and-wpf-introduction-and-building-your-first-window/

http://www.show-ui.com/

also, you can use visual studio community edition (free) or a paid tool such as https://poshgui.com/

alternatively, here is an example using the Show-Command cmdlet

function askforinfo {
    param (
        [string]$Demographics,
        [validateset(1, 2, 3)]
        [string]$otherstuff
    )
    [pscustomobject]@{
        Demographics = $Demographics
        OtherStuff = $otherstuff
    }
}

$result = Invoke-Expression (Show-Command askforinfo -PassThru)

$result
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, i tried your code that's exactly what i need, but i don't know how can i use individual input values as variables, i tried: $input1 = $result | Where-Object KeyName -eq 'Demographics' | Select-Object -ExpandProperty value And then $input1 But it doesn't return anything
try this $input1 = $result.Demographics
Wow! This is awesome :) What a "cheat".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.