Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Inputbox for Powershell

With [System.Windows.Forms.MessageBox]::Show(...) you can display a messagebox in every powershell script, but a function to display an inputbox is missing. So I wrote this small c# class InputBox for it.

Since Technet Gallery is closed, now here.

See Script Center version: Inputbox for Powershell.

Description

The class InputBox features:

  • automatic resizing to text sizes
  • default value
  • input of passwords
  • returns the pressed button and the input (in a referenced variable)

Remarks:

There's no need for dot sourcing the script cause it adds a type.

The referenced variable has to be declared or set before calling.

Examples:

all the examples assume the script is in the current directory

.\Start-InputBox.ps1
$Value = "default value"
if ([InputBox]::Show([ref] $Value, "Title to display", "Type in a text please") -eq "OK") { $Value } else { "Cancelled" }
.\Start-Inputbox.ps1
New-Variable PASS -Force
if ([InputBox]::Show([ref]$PASS, "", "Need password:", $TRUE) -eq "OK") { "Password stored" } else { "Cancel" }
.\Start-InputBox.ps1
New-Variable Inp -Force
[InputBox]::Show([ref] $Inp)