sorry, I keep trying to add more code, but it keeps bouncing out. Here’s what I added in shorter bites.
Process {
## Bypass if in non-interactive mode
If ($deployModeSilent) {
Write-Log -Message "Bypassing Installation Prompt [Mode: $deployMode]... $Message" -Source ${CmdletName}
Return
}
## Get parameters for calling function asynchronously
[hashtable]$installPromptParameters = $psBoundParameters
## Check if the countdown was specified
If ($timeout -gt $configInstallationUITimeout) {
[string]$CountdownTimeoutErr = "The installation UI dialog timeout cannot be longer than the timeout specified in the XML configuration file."
Write-Log -Message $CountdownTimeoutErr -Severity 3 -Source ${CmdletName}
Throw $CountdownTimeoutErr
}
[Windows.Forms.Application]::EnableVisualStyles()
$formInstallationPrompt = New-Object -TypeName 'System.Windows.Forms.Form'
$pictureBanner = New-Object -TypeName 'System.Windows.Forms.PictureBox'
$pictureIcon = New-Object -TypeName 'System.Windows.Forms.PictureBox'
$timerCountdown = New-Object -TypeName 'System.Windows.Forms.Timer'
$labelCountdown = New-Object -TypeName 'System.Windows.Forms.Label'
$labelTimeRemaining = New-Object -TypeName 'System.Windows.Forms.Label'
$labelText = New-Object -TypeName 'System.Windows.Forms.Label'
$buttonRight = New-Object -TypeName 'System.Windows.Forms.Button'
$buttonMiddle = New-Object -TypeName 'System.Windows.Forms.Button'
$buttonLeft = New-Object -TypeName 'System.Windows.Forms.Button'
$buttonAbort = New-Object -TypeName 'System.Windows.Forms.Button'
$InitialFormInstallationPromptWindowState = New-Object -TypeName 'System.Windows.Forms.FormWindowState' `
<code> ## Label Time Remaining $labelTimeRemaining.Location = '20,138' $labelTimeRemaining.Name = 'labelTimeRemaining' $labelTimeRemaining.Size = $buttonsize $labelTimeRemaining.TabIndex = 4 $labelTimeRemaining.Text = $timeout $labelTimeRemaining.TextAlign = 'MiddleCenter' ## Label Countdown $labelCountdown.Font = 'Microsoft Sans Serif, 18pt, style=Bold' $labelCountdown.Location = '170,200' $labelCountdown.Name = 'labelCountdown' $labelCountdown.TabIndex = 5 $labelCountdown.Text = '00:00:00' $labelCountdown.TextAlign = 'MiddleCenter' [datetime]$startTime = Get-Date [datetime]$countdownTime = $startTime ## Timer [datetime]$countdownTime = $startTime.AddSeconds($timeout) $timer = New-Object -TypeName 'System.Windows.Forms.Timer' $timer.Interval = ($timeout * 1000) $timer.Add_Tick({ Write-Log -Message 'Installation action not taken within a reasonable amount of time.' -Source ${CmdletName} $buttonAbort.PerformClick() }) $timer.Start() [timespan]$remainingTime = $countdownTime.Subtract($Starttime) $labelCountdown.Text = [string]::Format('{0}:{1:d2}:{2:d2}', $remainingTime.Hours, $remainingTime.Minutes, $remainingTime.Seconds)</code>