PowerShell Script To Send Message To Network Computer(s)
Some time back, we had a requirement to send a text message to all the client computers to inform about some activity.
I have created a this script which can send a POP UP MESSAGE to the computer(s). When you run the script it will simply prompt for inputs, and at the time of finish it will show you all the statistics.
The script can accept a single computer name or multiple computer names separated with comma (,) or path of txt file containing computers’ name, one in each line.
When you run this script it will ask you for below Input.
Message :- Type your message which you want to send to the computers. Like Hi, “Hello, Update are being installed on your computer, pleas wait” Etc.
Computer Name: – Type the computer name to which you want to send the message, if you type PC1, it will send message to PC1 computer.
You can type multiple computer names separated by the comma “,”. PC1, PC2, PC3 or you can give the path of the txt file which should have one computer name in each line.
Time :- Time :- Type time in SECONDS, duration till message pop up will remain on computer. After this time, the message pop up will disappear.
Like if you provide 5 in time prompt, the pop up will remain till 5 seconds on user’s desktop.

You can Download the script from here, or copy the below code and save as “.PS1” file.
<# Script to send message to Client computers using MSG utility.
The script will prompt you to enter the following information.
Message :- Type your message which you want to send to the computers. Like "Your computer is pending reboot after Windows updates, please reboot.."
Computer Name :- Type the computer name to which you want to send the Message, if you type PC1, it will send message to PC1 computer.
You can type multiple computer names separated by the comma “,” like PC1, PC2, PC3 or you can give the path of the txt file with computer names, one in each line.
Like below.
PC1
PC2
PC3
Time :- Type time in SECONDS, duration till message pop up will remain on computer. After this time, the message pop up will disappear.
For example if you provide 5 in time prompt, the pop up will remain till 5 seconds on user’s desktop.
#>
# Variable declaration
$Start_Time = Get-Date -Format T
$logFile = ‘Not_Reachable_PCs.txt’
$Message = Read-Host -Prompt “Type Your Message Here”
$ComputerName = Read-Host -Prompt “Type Computer Name Here”
$Time = Read-Host -Prompt “Type Time Here”
$Session = “*”
$ComputerName = $ComputerName -split ‘,’
if ($ComputerName -match “:”)
{
$Path = $ComputerName
$ComputerName = Get-Content $path
}
$Total = $ComputerName.count
foreach ($Computer in $ComputerName )
{
if (Test-Connection -ComputerName $Computer -Count 1 -ErrorAction 0)
{
Write-Host “Sending Message to $Computer…….” -ForegroundColor yellow
msg $Session /Server:$Computer /Time:$Time $Message
Write-Host “Message Successfully Sent to $Computer” -ForegroundColor Green
}
else
{
Out-File -FilePath $logFile -InputObject $Computer -Append -Force
Write-Host “$Computer is not Reachable…” -ForegroundColor red
}
}
$Not_Reachable_Count = @(Get-Content $logFile).count
$End_Time = Get-Date -Format T
$Minute = (New-TimeSpan -Start $Start_Time -End $End_Time).Minutes
$Second = (New-TimeSpan -Start $Start_Time -End $End_Time).Seconds
Write-Host Start at $Start_Time, End At $End_Time, Took About $Minute Minutes $seconds Seconds
Write-Host “Total $Total Computer Processed, $Not_Reachable_Count computers were offline. The list is stored in $logFile” -ForegroundColor white
hi and thank you for this wonderful script but I have a problem that it gives me msg.exe : Error opening Terminal server pc-14
At line:37 char:36
+ msg <<<< $Session /Server:$Computer /Time:$Time $Message
+ CategoryInfo : NotSpecified: (Error opening Terminal server pc-14:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Error [1722]:The RPC server is unavailable.
I disabled the firewall on all the computers and still gives me the same error any idea
Best
Please check the RPC Service on the remote and local computer and check the below reg key.
the following registry key must be activated
HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
Name : AllowRemoteRPC
Type : REG_DWORD
Value : 1
Please let me know if see any issue.
thank the problem is solved I did what you suggested
hi where i have to use this script?? Command prompt or other???
This is Power Shell script, you need to use Power Shell for this
Although, you can use command prompt but, ultimately you need to call Power Shell using a batch file.
and im confused how will i use this script??
Run this script with PowerShell, it will simply prompt you for the required input
Hi there. Thanks for the great work. I am testing the script and trying to send a message to two PCs on my network (one ismy own workstation). After going through the prompts it will send me the message but not to the other PCs although it says ‘Message successfully sent to…’. I have the other PC right beside me and I never see the message pop up? Thoughts?
Update! The above reply about turning on the AllowRemoteRPC key in the registry fixed it. Not too secure though. Thanks.
Thanks !
Can you please give me some brief that how are you using this ?
Also, can you use below command to send message to your computer for which you are using this script ?
msg * /Server:ComputerName /time:500 [Replace computer name with you orignal computer name]
Thanks !!
I changed “AllowRemoteRPC” registry entry like stated above. However, I am still getting, “msg : Error 5 getting session names”
Hi, nice write up. I could not run the ps. Getting the term is not recognized as the name of the commandlet. Any clues? Can u send the file as an attachment to me on thamola@yahoo.com
Sure. I will send you.
use lansend to send messages to multiple computers http://lizardsystems.com/lansend/
Hello,
I am getting the following error, would someone please help me diagnose the issue?
msg.exe : Error 5 getting session names
At C:\Users\NWhitlock\Downloads\MessageOut.ps1:61 char:36
+ msg <<<< $Session /Server:$Computer /Time:$Time $Message
+ CategoryInfo : NotSpecified: (Error 5 getting session names:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Please check the RPC Service on the remote and local computer and check the below reg key.
the following registry key must be activated
HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
Name : AllowRemoteRPC
Type : REG_DWORD
Value : 1
Please let me know if see any issue.
This reg. setting would need to be adjusted on each device over the network if this was to work, correct?
Correct, you can use GPO to do it.
Hello,
Thank you for script
How can we send message to domain computers or computers in OU.
You can export the list of computers from OU and then use it.
Hello how to reduce time in case if some of systems in between is not in network
This script will not broadcast the message, but will send message to all computers one by obe, you can split you list of computers to multiple list and then send it from different PS console.
HI Subodh,
can you please provide script to modify AllowRemoteRPC registry key to 1 on remote computers.
You need to allow below reg key.
HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server
Name : AllowRemoteRPC
Type : REG_DWORD
Value : 1
Do you have script to enable Registry key on remote computers
No, you can configure GPO to do that.
Is there anyway to add visuals to message
How can I modify your script to pull computer name from a text file?
Thank you! I didn’t notice you can put the file path of a text file with computer names…this is awesome!
Reblogged this on Duh! Microsoft did it again.
I guess SCCM can do this. Just research there are tools that uses a client software installed on your cluents The Script Worked perfectly in my Test Environment, but in the Production Environment it takes too Long to get executed. is there anything to help to quicken it?
Yes, it will take little long if you are sending to large amount of computers. But, with new Powershell versions you can reduce the time. Try to use foreach -parallel or just divide the input files and create multiple sessions to send.