Search notes:

Create a Message Box with PowerShell

The following example tries to demonstrate how the WinAPI function MessageBox (defined in user32.dll) can be called from PowerShell.
add-type -typeDefinition @"
using System;
using System.Runtime.InteropServices;
 
public static partial class user32 {

   [DllImport("user32.dll", CharSet=CharSet.Auto)]
    public static extern Int32 MessageBox(
            IntPtr hWnd,
            String text,
            String caption,
            int    options
    );
}
"@
 
$chosen = [user32]::MessageBox(0, 'Yes or no?' , 'Choose wisely', 4) # 4: MB_OKCANCEL

if ($chosen -eq 6) { # 6: ID_YES
   write-host "Yeah!"
}
else {               # 7: ID_NO
   write-host "Nay!"
}
Github repository about-PowerShell, path: /examples/message-box/user32-MessageBox.ps1
The message box in action:

See also

Alternatively (and possibly more easier), a message box can also be created using the .NET class System.Windows.Forms.MessageBox.
It is also possible to add WinAPI function with the cmdLet add-type.
System.Runtime.InteropServices
add-type
Other PowerShell examples

Index