If you’d like to show a default MessageBox with some buttons for the user to click, try this function:
[System.Windows.MessageBox]::Show($Text, $Caption, $Button, $Icon)
Write-Warning "Error occured: $_"
And here is how you’d use it:
PS> Show-MessageBox -Text 'Do you want to reboot now?' -Caption Reboot -Button YesNoCancel -Icon Exclamatio
ReTweet this Tip!
This is great to get the box to appear and click the desired button.
My question is ... Where do we enter the if statement to reboot the computer (if that is what we want to do)?
I see within the function there is a $button variable and I am guessing this is what the -Button YesNoCancel is assigned to, and selecting a button it is written to the host ... I am guessing this is the output.
Therefore I am wondering do we want to then pipe the output to an if statement EG IF Output = yes then Shutdown -f -r -t 0 Else exit or is it there a better way of doing it?
Show-MessageBox -Text 'Do you want to restart now?' -Caption "DONMAN Setup - Restart Required!" -Button YesNoCancel -Icon Exclamation
Powered by IDERA