Displaying InputBox

by Dec 10, 2015

To improve user-friendlyness, you could replace Read-Host by the following Show-InputBox function and get an inputbox dialog window:

#requires -Version 2
function Show-InputBox
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$true)]
        [string]
        $Prompt,
        
        [Parameter(Mandatory=$false)]
        [string]
        $DefaultValue='',
        
        [Parameter(Mandatory=$false)]
        [string]
        $Title = 'Windows PowerShell'
    )
    
    
    Add-Type -AssemblyName Microsoft.VisualBasic
    [Microsoft.VisualBasic.Interaction]::InputBox($Prompt,$Title, $DefaultValue)
}

Show-InputBox -Prompt 'Enter your name'

Twitter This Tip! ReTweet this Tip!