How to Show a Message Box on Windows 10 (PowerShell and Batch)

To show a custom message box on Windows 10, call the built-in Windows Forms MessageBox.Show method from Windows PowerShell. Run it once from a terminal or save it as a reusable .bat or .ps1 file. No administrator account is needed in your signed-in desktop session.

A message box is a modal dialog that stays open until dismissed and can block interaction with its owner. It differs from a toast notification. Microsoft's MessageBox.Show reference lists the message, caption, button, and icon arguments.

Choose how to show the message

  • One-time dialog: run a short command in PowerShell.
  • Run it from Command Prompt: start Windows PowerShell with powershell.exe.
  • Reuse it later: save the command as a batch file or PowerShell script.

The examples use Windows PowerShell and the System.Windows.Forms assembly available on Windows. The command loads that assembly, then specifies the message, title, OK button, and information icon.

Create a reusable batch file

  1. Open Notepad from the Start menu. A blank document is enough for this short script.
    A blank Notepad window with the cursor at the start of the document.
    Open a blank Notepad document before entering the script.
  2. Paste these two lines:
    @echo off
    powershell.exe -NoProfile -Command "Add-Type -AssemblyName System.Windows.Forms; [void][System.Windows.Forms.MessageBox]::Show('Backup complete.', 'Backup status', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)"
    Notepad with the opening lines of a batch file: @echo off and a PowerShell command.
    The batch file starts PowerShell without loading a profile.
  3. Change Backup complete. to the text you want and Backup status to the title. Keep the single quotes around both strings. The explicit button and icon values make the dialog predictable; [void] discards the method's return value because this example only needs to display the box.
    Notepad showing a Windows Forms message box call with a custom title, message, OK button, and information icon.
    Set the message and title in the MessageBox.Show call.
  4. Choose File > Save As. Enter ShowMessage.bat as the file name and select All Files as the file type, then save it somewhere easy to find, such as the Desktop. If you leave the type as a text document, Notepad may save it as ShowMessage.bat.txt instead.
    The Windows Save As dialog with ShowMessage.bat entered as the file name and All Files selected.
    Save with the .bat extension and choose All Files.
  5. Open the saved ShowMessage.bat file. The message box appears; click OK to close it.
    File Explorer with ShowMessage.bat selected on the Desktop.
    Run the saved batch file from File Explorer.
    A Windows information dialog titled Backup status with the message Backup complete and an OK button.
    The custom message box stays open until OK is selected.

Because the batch file nests PowerShell inside a quoted command, keep the text simple and avoid double quotation marks in the message and title.

Run the command directly in PowerShell

  1. Open Windows PowerShell from Start.
    A Windows PowerShell window open at a prompt.
    Open Windows PowerShell for a one-time command.
  2. Paste the following command and press Enter:
    Add-Type -AssemblyName System.Windows.Forms
    [void][System.Windows.Forms.MessageBox]::Show('Backup complete.', 'Backup status', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
    A PowerShell window with Add-Type and a MessageBox.Show command entered.
    Load Windows Forms, then call MessageBox.Show.
  3. Click OK when the dialog appears.
    A Windows information dialog displaying Backup complete under the title Backup status.
    The PowerShell command displays the requested message.

For a reusable PowerShell script, save the two PowerShell lines above in Notepad as ShowMessage.ps1, choosing All Files. Run a Desktop copy with & "$env:USERPROFILE\Desktop\ShowMessage.ps1". If an execution policy blocks the script, use the inline command or batch file rather than changing a device-wide policy. See Microsoft's Add-Type documentation.

Show a message from Command Prompt

In Command Prompt, paste this one-line command and press Enter. It starts Windows PowerShell and passes it the dialog code:

powershell.exe -NoProfile -Command "Add-Type -AssemblyName System.Windows.Forms; [void][System.Windows.Forms.MessageBox]::Show('Backup complete.', 'Backup status', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)"
Command Prompt containing a powershell.exe command that calls a Windows Forms message box.
Command Prompt can pass the same dialog call to PowerShell.

The dialog appears over the desktop; close it with OK, then Command Prompt returns to its prompt. The -NoProfile switch starts PowerShell without loading the user's profile, as described in Microsoft's Windows PowerShell command-line reference.

A Windows information message box titled Backup status with an OK button on the desktop.
Close the dialog to return to the Command Prompt.

Use Yes and No buttons

To ask a question, change the button and icon arguments, then check the result. The method returns a DialogResult, so your script can take a different action depending on the answer:

$answer = [System.Windows.Forms.MessageBox]::Show('Continue with cleanup?', 'Confirm action', [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Question)
if ($answer -eq [System.Windows.Forms.DialogResult]::Yes) { 'Continue with cleanup' } else { 'Cancelled' }
A Windows confirmation dialog titled Confirm action with Yes and No buttons.
Use Yes and No when the script needs a user decision.

PowerShell single-quoted strings treat most characters literally. If your message itself contains an apostrophe, double it inside the string (for example, 'Don''t close this window'). See Microsoft's PowerShell quoting rules. For a batch command, also avoid double quotes inside the message because the command is nested inside a quoted -Command argument.

If the message box does not appear

  • Confirm the file ends in .bat or .ps1, not .txt.
  • Run it in a signed-in desktop session; a service or noninteractive process may not show UI there.
  • Use Alt+Tab if the dialog may be behind another window.
  • If a saved script fails, try the inline command to isolate file-name or quoting errors.

If all you need is a reminder that should not interrupt the current task, use a Windows notification instead of this modal dialog. For a simple custom pop-up that must be acknowledged, the PowerShell method above is the shortest route.

Leave a Comment

How to Play Minecraft Offline on Windows 10: Java and Bedrock

How to Play Minecraft Offline on Windows 10: Java and Bedrock

Prepare Java or Bedrock on Windows 10 for offline single-player, enable the right Xbox setting, and back up your local Minecraft worlds.

How to Change a File Type Icon in Windows 10

How to Change a File Type Icon in Windows 10

Change a file type icon in Windows 10 while keeping its current default app. Follow the FileTypesMan steps, handle icon picker issues, and restore the original setting.

How to Set PhysX Configuration in NVIDIA Control Panel on Windows 10

How to Set PhysX Configuration in NVIDIA Control Panel on Windows 10

Set PhysX in NVIDIA Control Panel on Windows 10, understand Auto-select vs. CPU or GPU, and learn when to use Windows Graphics settings instead.

Best Free Office Software: 6 Alternatives to Word, Excel, and PowerPoint

Best Free Office Software: 6 Alternatives to Word, Excel, and PowerPoint

Compare six free office suites for documents, spreadsheets, and presentations, including browser-based collaboration and offline desktop options.

How to Get Line Numbers in Notepad on Windows 10

How to Get Line Numbers in Notepad on Windows 10

Turn on Notepad’s Status Bar to see the current line and column in Windows 10, troubleshoot a disabled option, and learn when you need a line-number gutter.

How to Show a Message Box on Windows 10 (PowerShell and Batch)

How to Show a Message Box on Windows 10 (PowerShell and Batch)

Display a custom Windows dialog with a short PowerShell command, Command Prompt, or a reusable .bat or .ps1 file, including a title, icon, and buttons.

How to Fix Windows 10 Update Error 0x80071160

How to Fix Windows 10 Update Error 0x80071160

Fix Windows 10 update error 0x80071160 with Microsoft’s troubleshooter, a safe update-cache reset, DISM and SFC repairs, and a careful manual-install check.

How to Install Windows 10 From a UEFI Bootable USB

How to Install Windows 10 From a UEFI Bootable USB

Create a Windows 10 UEFI installer with Microsoft’s Media Creation Tool or Rufus, then boot and install safely without wiping the wrong drive.

How to Hide Microsoft Edge Tabs from Alt+Tab in Windows 10

How to Hide Microsoft Edge Tabs from Alt+Tab in Windows 10

Stop individual Edge tabs from crowding the Windows 10 Alt+Tab switcher. Change one Multitasking setting, limit recent tabs, and check why the option may be missing.

How to Fix PDF Thumbnails Not Showing in Windows 10

How to Fix PDF Thumbnails Not Showing in Windows 10

Enable Adobe’s PDF thumbnail handler, correct File Explorer’s icon settings, rebuild the thumbnail cache, and check OneDrive files that are not stored locally.