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!
Thanks for the shoutout postanote! The documentation linked above has a new home:
Also, see the new quickstart guide on my GitHub:
Glad you like the AnyBox!
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
Add this first and see if that helps: Add-Type -AssemblyName PresentationFramework
One could also just do this..
Or just use this module
Designed to facilitate script input/output with an easily customizable WPF window.
Authors site - instructions -
All I get is this:Unable to find type [Windows.MessageBoxButton].At line:15 char:4+ [Windows.MessageBoxButton]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Windows.MessageBoxButton:TypeName) , RuntimeException + FullyQualifiedErrorId : TypeNotFound
Using Windows 7 I cannot see all the icons. Will they appear in Windows 10? Is there are way to path to my own icons?
Powered by IDERA