For each of my scripts I try to make them as easy as possible so that I have as little effort as necessary to solve an already solved problem again when I use it one more time.
To make this possible, I often use input boxes.
Enclosed you will find a short instruction how to implement this:
Example 1 - Input Form:
# Loading the VisualBasic Assembly
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
# Creation of an input form, labelled according to your needs with a predefined input value
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your name", "Name", "$env:username")
# Display of the value specified in the form
"Your name is $name"
Example 2 - Input Question Form:
# Loading the VisualBasic Assembly
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
# Creation of an input question form, labelled according to your needs
$result = [Microsoft.VisualBasic.Interaction]::MsgBox( `
"Do you agree?", 'YesNoCancel,Question', "Respond please")
# Response dependent actions (Switch)
switch ($result) {
'Yes' { "Ah good" }
'No' { "Sorry to hear that" }
'Cancel' { "Bye..." }
}
Reference: