I have a requirement to display a message on the screen asking the user to plug in their device. I want the message to be persistent and automatically disappear once the power has been connected.
The latter I can do with Show-ADTInstallationProgress but this can be minimized. The former I can do with Show-ADTInstallationPrompt but other than having it time out and then reappear (which is messy) I can't see a way to get this to disappear automatically.
Potentially I could spawn a child process that runs Show-ADTInstallationPrompt but was wandering if the hive mind had any better ideas.
It seems that there may be other use cases for an option to keep a window open until a scriptblock returns as $true (or $false, take your pick).
I have an idea.
First, create a Test-DeviceIsPluggedIn function
Then do something like the following in your PSADT script
If (-Not (Test-DeviceIsPluggedIn)) {
Show-ADTInstallationPrompt -StatusMessageDetail "Please plug the device in!"
$Count = 0
Do {
#Now we wait for the user
Start-Sleep -seconds 3
$Count++
Until ((Test-DeviceIsPluggedIn) -or ($count -gt 20))
}
If (Test-DeviceIsPluggedIn) {
Show-ADTInstallationPrompt -StatusMessageDetail "Thank you for plugging-in the device."
} Else {
Show-ADTInstallationPrompt -Message "Device NOT plugged-in. Failing the Installation of $($adtSession.InstallTitle)" -ButtonRightText 'OK' -Icon Error -NoWait #NoWait make the message stay after the install is closed.
}
#Proceed with installation as normal
CAVEAT: Untested.
Firstly, @That-Annoying-Guy, thank you for responding.
I could be wrong but Show-ADTInstallationPrompt doesn't seem to have the parameter "StatusMessageDetail". Show-ADTInstallationProgress does but that can be minimized.
By default Show-ADTInstallationPrompt stops the script from running so I can't run check for the device being plugged in (I'm using (Test-ADTBattery).isUsingACPower). I've found the "noWait" parameter but can't work out how (short of killing the PSADT.ClientServer.Client process indiscriminately) how to get rid of the prompt again. I had hoped that the Close-ADTInstallationProgress cmdlet may be able to do something but as the name suggest it only looks at Installation Progress windows.
I have found a third-party script that can change the state of windows of a given process (in my case allowing me to restore them) that I can use with the Show-ADTInstallationWelcome cmdlet. This is also a little indiscriminate (as I have no way to know which PSADT.ClientServer.Client process is connected to my window) but less of a problem since it's only restoring the window not killing the project. (One would hope there would only be one of these processes running at any one time but best not to assume that!)
I guess if immediately before and after I generate the window I get all the PSADT.ClientServer.Client processes I could just target those that appear in between, while not perfect it's a lot more descriminating.
My apologies, I picked the wrong version of PSADT.
I also meant to use Show-ADTInstallationPrompt only once.
If (-Not (Test-DeviceIsPluggedIn)) {
Show-ADTInstallationProgress -StatusMessage "Please plug the device in!"
$Count = 0
Do {
#Now we wait for the user
Start-Sleep -seconds 3
$Count++
Until ((Test-DeviceIsPluggedIn) -or ($count -gt 20))
}
If (Test-DeviceIsPluggedIn) {
Show-ADTInstallationProgress -StatusMessage "Thank you for plugging-in the device."
} Else {
Show-ADTInstallationPrompt -Message "Device NOT plugged-in. Failing the Installation of $($adtSession.InstallTitle)" -ButtonRightText 'OK' -Icon Error -NoWait #NoWait make the message stay after the install is closed.
}
#Proceed with installation as normal