+3  A: 

Try this way:

[windows.forms.messagebox]::show('body','title','YesNo')

And the distinction between using :: and . is static method vs instance method. Notice above that we didn't create a MessageBox object. We are just using a static method on MessageBox with the :: syntax.

Keith Hill
Ok for :: vs ., but your solution does not work (same message as the OP)... maybe an overload resolution problem... should be ok with an explicit cast
Cédric Rup
I have verified that it works on both PowerShell 1.0 and 2.0. Are you sure you're pulling in the Windows Forms assembly: Add-Type -AssemblyName System.Windows.Forms?
Keith Hill
the assembly was added. I'm still using a CTP here. Oh, and the message is 'Multiple ambiguous overloads found for "Show" and the argument count: "3"'.
Cédric Rup
I wonder if this was an issue fixed between CTP and the final release??
Keith Hill
Looks like it ;o)
Cédric Rup
It worked once the third parameter was no longer null.
Andrew J. Brehm
+2  A: 

Correct way of doing this can be

$buttons=[system.windows.forms.messageboxbuttons]::yesno;
[system.windows.forms.messagebox]::Show("Are you sure?","",$buttons);

Notice "::" instead of "." in the first line. YesNo value is defined staticly on System.Windows.Forms.Messageboxbuttons, so you must use "::" (static call) instead of "."

Note that "[system.windows.forms.messageboxbuttons].yesno" is an attempt to call a "YesNo" property on an instance of System.Type, which does not exist and therefore result in a $null

Hope it helps !

Cédric

Edit ---

Keith solution using an implicit cast made by powershell for the enum is more elegant. It just does not work on PS V2 CTP 3 which I still use but work fine on RTM version. The complete explication was worth giving, though...

Cédric Rup
I figured :: was for a static call but then couldn't explain to myself why PowerShell would make that difference. It is clear that MessageBox is a class, not an object; hence :: instead of . seems unecessary. Why add more precise syntax if the interpreter doesn't need it AND it confuses the user?
Andrew J. Brehm
Depending on the syntax used (ie :: or .), [YourType] is the equivalent of C# typeof(YourType) or a path to access static methods. The interpreter needs it to know what you want to do ! How would you do ?
Cédric Rup
I think I would do it like in C#.
Andrew J. Brehm