Add custom buttons to a message box in Powershell

Viewed 947

TL;DR

Is there a way to change the default button options with message boxes in PowerShell?


Full

Recently, I was playing around with message boxes in PowerShell. So, I used the code below.

Add-Type -AssemblyName PresentationFramework

$result = [System.Windows.MessageBox]::Show("Would you like to use v1 or v2?", "Version Choice", "YesNo", "Information", "Yes")
Write-Host $result

And it works as intended.

Popup


However, I was wondering if there was a way to add a custom option in the buttons to show. Right now, these are the only available button values.

  • AbortRetryIgnore
  • CancelTryContinue
  • OK
  • OKCancel
  • RetryCancel
  • YesNo
  • YesNoCancel

Can you add a custom button value? Something like...

[System.Windows.MessageBox]::Show("Would you like to use v1 or v2?", "Version Choice", "V1V2", "Information")

Or...

[System.Windows.MessageBox]::Show("Would you like to use v1 or v2?", "Version Choice", @("V1", "V2"), "Information")

However, when I try these, it comes up with an error.

Cannot convert argument "button", with value: "V1V2", for "Show" to type "System.Windows.MessageBoxButton": "Cannot convert value "V1V2" to type 
"System.Windows.MessageBoxButton". Error: "Unable to match the identifier name V1V2 to a valid enumerator name. Specify one of the following enumerator names and try 
again

A similar error occurs when trying with the arrays.


Conclusion

In conclusion, is it possible to change the default buttons in the message box?

0 Answers
Related