Send A Message To A Remote Computer

I thought I would share this one as I recently had the need to write it. I’m semi lucky to work with someone I call a friend and knew before we both got jobs here, and I would say I am the more childish one.

Anyway, one day he was being slow to respond to me on teams, and I am sure there are much better things you can do than this, but I decided to send him a message which appear in the middle of his screen and would make him have to click the Ok button to get it to go. If he didnt respond to me in teams then I would send it again and again until he did.

Its nothing special but here it is

$computerName = "RemoteComputer"
$message = "Hello, World!"
$msgCommand = "msg.exe * /server:$computerName $message"
Invoke-Expression $msgCommand

In this script, you need to replace “RemoteComputer” with the name of the remote computer you want to send the message to, and “Hello, World!” with the message you want to send. The Invoke-Expression cmdlet is used to execute the msg.exe command with the specified arguments.

Note that the msg.exe command requires that the Remote Desktop service is running on the remote computer and that the user account you are using to run the script has administrative privileges on the remote computer.

Leave a Reply

Your email address will not be published. Required fields are marked *