Skip to content

Instantly share code, notes, and snippets.

@hobelinm
Created March 9, 2014 06:49
Show Gist options
  • Save hobelinm/9443818 to your computer and use it in GitHub Desktop.
Save hobelinm/9443818 to your computer and use it in GitHub Desktop.
Simple dialog box in PowerShell
# Load libraries
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
# Selection box
$input = [Microsoft.VisualBasic.Interaction]::MsgBox("Do you agree?", 'YesNoCancel,Question', "Respond Please")
# Process input as desired
switch($input)
{
'Yes'
{
Write-Host "Good Choice" -ForegroundColor Green
}
'No'
{
Write-Host "You've selected No" -ForegroundColor Red
}
'Cancel'
{
Write-Warning "Exiting this script..."
}
}
# General input box
$info = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Some Data", `
"Title box", "Initial Default Value")
# Shows what the user entered
Write-Host $info -ForegroundColor Cyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment