Site icon WindowsLoop

PowerShell Script To Display a Message Box in Windows

PowerScript to show message box featued image

Have you ever wanted to show a simple message box with a custom message on your PC? You can do it using my PowerShell script given below. When executed, it shows the message you want. If needed, you can automatically execute the script whenever you want using the Task Scheduler application in Windows.

For instance, I recently changed the folder structure of an important directly and to let other users know about it, I displayed a custom message box on startup with relevant information and a file path where they can learn more and find new instructions.

So, without further ado, let me show you the PowerShell script to display a custom message and how to use it.

PowerShell Script to Display Custom Message

Here’s the PowerShell script that displays a message box with the custom message of your choice when run.

<#
  Script Name: MessageBox Display Tool
  Description: This script displays a message box with a custom message and title using Windows Forms.
  Author: Bashkarla Vamsi
  URL: https://windowsloop.com
#>

# Load Windows Forms for GUI message box
Add-Type -AssemblyName System.Windows.Forms

# Define the message box parameters
$message = "Hello, this is your message!"
$title = "Custom title for your message box"

# Display the message box
[System.Windows.Forms.MessageBox]::Show($message, $title)

Using the Script to Display the Message Box with a Custom Message

Save the Script & Customize it

First, press the Start button, search for Notepad, and click Open.

Copy (Ctrl + C) the script and paste (Ctrl + V) it into the Notepad.

After that, customize the $message and $title variables to add your custom message and message box title within the quotes respectively.

Click the File and Save As option.

Go to a folder where you want to save the file, enter ShowMessageBox.ps1 as the “File Name” field, select All Files from the “File Types” dropdown, and click Save.

Execute the Script

To run PowerShell scripts, the first thing you should do is change the execution policy. Otherwise, you will not be able to execute scripts, even if you are the one who created the script.

To do that, right-click the Start button and select Terminal (Admin) or Windows PowerShell (Admin).

Type the below command and press Enter to set the execution policy.

Set-ExecutionPolicy RemoteSigned

Next, use the CD command as shown below to navigate to the folder where the PS Script is saved.

cd C:\path\to\script

Type .\ShowMessageBox.ps1 and press Enter to run the script.

Schedule the Script to Run Automatically

For those who want to run the PowerShell script automatically on system startup, add it to the Startup folder. Alternatively, you can also use the Task Scheduler as shown below to run the script on schedule. The task scheduler method is especially useful to trigger the script on specific system events.

First, press the Start button, search for Task Scheduler, and click Open.

Click on Create Basic Task in the Task Scheduler window.

Enter a name of your choice in the “Name” field and click Next.

Select a trigger and click Next. I am selecting the “When the computer starts” trigger so that the script runs as soon as the computer starts and a user logs in.

Select Start a Program and click Next.

Enter powershell.exe in the “Program/Script” field. In the “Add arguments” box, type -File "C:\Path\To\YourScript.ps1". Replace C:\Path\To\YourScript.ps1 with the path to your PowerShell script. Click Next.

Click the Finish button and you are done.

From now on, the PowerShell script executes according to the schedule and shows a message box with your custom message.

Wrapping Up — Message Box With a Simple PowerShell Script

As you can see, this is a pretty simple and straightforward PowerShell script to display a message with a custom message on your desktop. It uses the .NET Framework’s System.Windows.Forms assembly to build a message box, add your custom message and display it to users. If you want the script to run on startup or a specific event, use the Task Scheduler as shown.

If you have any questions, comment below and I will answer.

Exit mobile version