Add the ability to accept user input from Show-Installation Prompt

Topics: Archive - Toolkit Extensions
Nov 11, 2014 at 7:34 PM
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.
Dec 10, 2014 at 12:07 PM
I would like something like this for our suite of application products we have for users. Basically we are going to leverage the SCCM app store for our users and present to them a package suite in which they would request download from the app store. This suite would essentially be user interface they download that gives them a UI a list of check boxes to pick which applications from the suite they would like to install. ON the back end essentially they would check a box which drops their machine into a deployment collection for the application they selected. I am just trying to see if this would be feasible with this tool or not...