I'm trying to display a timer in my message box that I created with PS Forms. I would like something like that:
" Your PC will be shutdown in 10 sec" after 1 sec.
"Your PC will be shutdown in 9 sec"
"Your PC will be shutdown in 8 sec" and so on.
Hope you can help me.
I don't see a way of refreshing the text in a message box. If I had to do this I would probably pop up another form with a label and use a timer that refreshes the text of the label on each tick.
Here is a code example to use a potential starting point:
You will need to expand to meet your needs such as conditional logic to do whatever action you want (e.g., reboot) when the count down reaches 0, perhaps add a button for aborting, etc.
There's PopUp Method from Windows Script Host, that enables you to set a
time to live
for thePopUp
. I don't think that there is a way no refresh a message box from PowerShell (don't quote me on that). Two lines of the code came from here.Not sure if it's this that you want, but this works (crude solution):
EDIT : The solution presented by @JonDechiro is much cleaner than mine and more apropriate for what OP asked.