I recently had a situation where I needed to be able to accept input from the user in order to complete an installation. I modified Show-InstallationPrompt to allow for the creation of a textbox as well as the return of that information.
I added a Parameter of ShowTextBox which controls whether or not the TextBox is displayed on the screen.
.PARAMETER ShowTextBox
Specifies whether to create a textbox [Default is false]
Add this to your Param section:
[boolean] $ShowTextBox = $false,
This goes after the Param block:
$textBox = New-Object System.Windows.Forms.TextBox
# Textbox
$textBox.DataBindings.DefaultDataSourceUpdateMode = 0
$textBox.Location = "100,150"
$textBox.Name = "textBox"
$textBox.Size = "260,20"
$textBox.AutoSize = $true
Under the Form Installation Prompt Section, I added the following:
If ($ShowTextBox) {
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 98 #148
$System_Drawing_Size.Width = 385
$labelText.Size = $System_Drawing_Size
$formInstallationPrompt.Controls.Add($textBox)
}
Since we want to get back the information that the user has entered into the textbox, we have to modify the code at the end of the existing function. So we need to replace the section below:
Switch ($result) {
"Yes" { Return $buttonRightText}
"No" { Return $buttonLeftText}
"Ignore" { Return $buttonMiddleText}
"Abort" {
# Restore minimized windows
$shellApp.UndoMinimizeAll()
If ($ExitOnTimeout -eq $true) {
Exit-Script $configInstallationUIExitCode
}
Else {
Write-Log "UI timed out but ExitOnTimeout set to false. Continuing..."
}
}
}
With this newly updated code (I am sure that there is a prettier way to do this, I was in a hurry):
```
If ($ShowTextBox) {
Switch ($result) {
"Yes" { Return $textBox.Text}
"No" { Return $textBox.Text}
"Ignore" { Return $textBox.Text}
"Abort" {
# Restore minimized windows
$shellApp.UndoMinimizeAll()
If ($ExitOnTimeout -eq $true) {
Exit-Script $configInstallationUIExitCode
}
Else {
Write-Log "UI timed out but ExitOnTimeout set to false. Continuing..."
}
}
}
}Else{
Switch ($result) {
"Yes" { Return $buttonRightText}
"No" { Return $buttonLeftText}
"Ignore" { Return $buttonMiddleText}
"Abort" {
# Restore minimized windows
$shellApp.UndoMinimizeAll()
If ($ExitOnTimeout -eq $true) {
Exit-Script $configInstallationUIExitCode
}
Else {
Write-Log "UI timed out but ExitOnTimeout set to false. Continuing..."
}
}
}
}
I hope that this helps someone else who needs to accept input from the Show-InstallationPrompt.