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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1758199877, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/examples/message-box(79): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78