Skip to content

PowerShell: display a message on a remote user’s computer

A user isn’t answering the phone or email, and you need to warn them before restarting their PC. PowerShell can display a window on their screen in one command, provided remote management is enabled.

dMessage sending console with a message ready to send

Check the prerequisites on the remote PC

The most reliable method is to run msg.exe directly on the target PC, using PowerShell remoting. Check three things before the first send.

  1. WinRM is enabled. On a domain, it is often enabled by Group Policy. Otherwise, run Enable-PSRemoting as an administrator on the PC.
  2. Your account is an administrator on the PC. By default, only local administrators can open a remote PowerShell session.
  3. msg.exe is present. The command exists on Windows Pro and Enterprise editions, not on Home.
Test-WSMan -ComputerName PC-COMPTA-07

If the command returns a response from the WS-Management service, the connection is possible.

See who is signed in

msg.exe shows nothing if nobody has signed in. Start by querying the PC.

Invoke-Command -ComputerName PC-COMPTA-07 -ScriptBlock { query user }

The user’s session should appear with the Active state. A disconnected session stays open, but nobody is in front of the screen.

Display the message

$message = "Your PC will restart at 12:30 for an update. Save your files. Support: 4455."
Invoke-Command -ComputerName PC-COMPTA-07 -ScriptBlock {
    msg * /time:600 $using:message
}

The asterisk sends the window to every session open on this PC. The /time:600 option keeps it on screen for ten minutes instead of the default 60 seconds. The $using: prefix passes the local variable to the remote PC.

Do a first test on a test PC. Check how accented characters display and the length of the text.

Common pitfall

msg.exe doesn’t exist on Windows Home. On those PCs, the script fails and the user sees nothing.

Alerting every PC in a department

For a whole department, retrieve the computers in its organisational unit in Active Directory. The ActiveDirectory module from the RSAT tools is required. The script records each PC’s result in a CSV file.

$message = "File server down from 12:30 to 13:00. Save your documents."
$computers = Get-ADComputer -Filter * -SearchBase "OU=Comptabilite,DC=contoso,DC=local" |
    Select-Object -ExpandProperty Name

$results = foreach ($computer in $computers) {
    try {
        Invoke-Command -ComputerName $computer -ErrorAction Stop -ScriptBlock { msg * /time:600 $using:message }
        [pscustomobject]@{ Computer = $computer; Result = "Sent" }
    } catch {
        [pscustomobject]@{ Computer = $computer; Result = $_.Exception.Message }
    }
}
$results | Export-Csv .\message-results.csv -NoTypeInformation -Encoding UTF8

Invoke-Command can also target several PCs at once, with 32 simultaneous connections by default. The loop is slower, but it shows which PCs didn’t receive the message: switched off, off the network or without WinRM.

A “Sent” line means the command ran on the PC. It doesn’t prove that anyone read the window.

60 s

msg.exe default display time

32

simultaneous connections by default with Invoke-Command

0

read receipts recorded by msg.exe

Limits to be aware of

  • No read receipts. The /w option waits for the user to close the window, PC by PC. It doesn’t produce a list of people who have read the message.
  • Plain text. No title, no urgency level, no attachment. A security alert looks just like a meeting reminder.
  • Targeting by computer. The script targets the PCs in an OU, not the people in a group. A colleague signed in on another PC receives nothing.
  • Prerequisites on every PC. WinRM, administrator rights and firewall rules must be in place. PCs that are switched off or off the network fail.
  • A script to run under pressure. During an incident, writing and running the script takes time. Better to prepare messages in advance.

When to move to a dedicated tool

dMessage sending console and the message received on the PC
The dMessage sending console, with the message as it appears on the PC.

To alert a whole department regularly, or to know who has read an instruction, dMessage targets Active Directory users and groups directly. Templates are prepared in advance and read receipts are recorded. You know who has read it, and who to chase. Here is the same message, sent to the Accounts group.

File server downtime

Warning

From: IT Support

Hello,

The file server will be down from 12:30 to 13:00 for an update.

Save your documents before 12:30.

For anything urgent, call support on 4455.

French
Example dMessage message sent to the Accounts Active Directory group.

The PowerShell script is still useful for a one-off need. With dMessage, sending doesn’t depend on WinRM: the agent installed on PCs displays the messages prepared in the console.

Safran, Amundi and France’s Conseil d’État use dMessage

Compare it with your script on three PCs

Install the evaluation version, send this message to a small Active Directory group and see who has read it. It’s free for 30 days.

Download the free trialSee pricing

Understand MSG command syntax and permissions · Try dMessage for 30 days

Sources: msg command documentation · Invoke-Command documentation