Create Input Box PowerShell

Create Input Box PowerShell


If you write script for your help desk or non-initiated PowerShell people, you might want to simplify the PowerShel tools you provide to them. You may still need them to input a username or a mail address as input for your script to run only on a targeted user/mailbox.

Create Input Box PowerShell – Old way

There is a way to create an input box in PowerShell and then use the content inserted in it in your script.

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$User = [Microsoft.VisualBasic.Interaction]::InputBox('Enter a user name', 'User', "$env:UserName")

You may noticed the “LoadWithPartialName” static method which is obsolete :

Create Input Box PowerShell - Obsolete API

Create Input Box PowerShell – Obsolete API

Create Input Box PowerShell – New way

The new way of loading assembly os with “Add-Type” cmdlet, so here we go :

Add-Type -AssemblyName Microsoft.VisualBasic
$User = [Microsoft.VisualBasic.Interaction]::InputBox('Enter a user name', 'User', "$env:UserName")
Create Input Box PowerShell - New Way

Create Input Box PowerShell – New Way

Once the help desk guy clicked on “Ok”, the $User variable will contain the value that was in the textbox, and then you can apply some regex/validation on it, and then use it to act on Active Directory account or mailboxes.

You can combine this with a precedent article of mine, and then build some basic Graphical User Interface (GUI) for your help desk users.

You can also checkout my GUI tag to find more way to build GUI with PowerShell.

4 thoughts on “Create Input Box PowerShell

  1. Hi,

    Is it possible to manually increase the size (length) of the InputBox if the title is too long and cut?

    Thank you for your advice.

  2. I know this is an old post but I have found it useful, thank you. Do you know how to validate the user input though? I mean, the script just moves to the next step whether the user enters a value or not and clicks OK or Cancel. I need to determine that there is a value and the user clicked OK before some more script steps occur. I tried if ($User <> 0) {…..} but couldn’t get it to work.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.