Answered by:
Send message to the users

Question
-
Hi,
Everytime when we need to reboot the system we need to send an email to the users that are logged on the servers. It happened a lot that users don't read mail and because of that, they never log off. To prevent data loss, is there a way to send message via powershell so that message pop-up on the screen?
Monday, October 9, 2017 5:50 AM
Answers
-
Hi,
Try this one. It will send msg to the computers in the computers ou. You can modify it so that fits your req
(Get-ADComputer -SearchBase "OU=Computers,DC=domain,DC=com" -Filter *).Name | Foreach-Object {Invoke-Command -ComputerName $_ {msg * "Please close all open files. The Server will be shut down in 5 Minutes"}}
Please remember to mark the replies as answers if they help.,
NEDIMMEHIC.ORG- Edited by Nedim Mehic Monday, October 9, 2017 5:55 AM
- Marked as answer by D-TOXXX Monday, October 9, 2017 11:47 AM
Monday, October 9, 2017 5:54 AM -
Use PowerShell to run it in a loop with a list of computers.
Since you are not a PowerShell scripter then you can just put 10 lines in a batch file with the message and one computer per line.
\_(ツ)_/
Monday, October 9, 2017 7:22 AM -
Use PowerShell to run it in a loop with a list of computers.
Since you are not a PowerShell scripter then you can just put 10 lines in a batch file with the message and one computer per line.
\_(ツ)_/
Why would he do that? Did you check my command? With that command you can send message to all servers in an OU.
(Get-ADComputer -SearchBase "OU=Computers,DC=domain,DC=com" -Filter *).Name | Foreach-Object {Invoke-Command -ComputerName $_ {msg * "Your message"}}
Please remember to mark the replies as answers if they help.,
NEDIMMEHIC.ORG- Marked as answer by D-TOXXX Monday, October 9, 2017 11:48 AM
Monday, October 9, 2017 7:27 AM
All replies
-
This is a basic Windows utility and does not require PS.
msg /?
\_(ツ)_/
- Edited by jrv Monday, October 9, 2017 5:56 AM
Monday, October 9, 2017 5:55 AM -
Hi
Check this out
https://community.spiceworks.com/scripts/show/2597-send-a-pop-up-message-to-a-single-computer
NTRao
Monday, October 9, 2017 6:18 AM -
No one seems to know how to read the instructions:
No need for any kind of remoting. Just use MSG.
MSG {username | sessionname | sessionid | @filename | *}
[/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]It is critical to learn how to read instructions if you want to be a technician or scripter.
\_(ツ)_/
Monday, October 9, 2017 6:51 AM -
Hi,
Try this one. It will send msg to the computers in the computers ou. You can modify it so that fits your req
(Get-ADComputer -SearchBase "OU=Computers,DC=domain,DC=com" -Filter *).Name | Foreach-Object {Invoke-Command -ComputerName $_ {msg * "Please close all open files. The Server will be shut down in 5 Minutes"}}
Please remember to mark the replies as answers if they help.,
NEDIMMEHIC.ORG
Monday, October 9, 2017 7:16 AM -
No one seems to know how to read the instructions:
No need for any kind of remoting. Just use MSG.
MSG {username | sessionname | sessionid | @filename | *}
[/SERVER:servername] [/TIME:seconds] [/V] [/W] [message]It is critical to learn how to read instructions if you want to be a technician or scripter.
\_(ツ)_/
Monday, October 9, 2017 7:17 AM -
Use PowerShell to run it in a loop with a list of computers.
Since you are not a PowerShell scripter then you can just put 10 lines in a batch file with the message and one computer per line.
\_(ツ)_/
Monday, October 9, 2017 7:22 AM -
Use PowerShell to run it in a loop with a list of computers.
Since you are not a PowerShell scripter then you can just put 10 lines in a batch file with the message and one computer per line.
\_(ツ)_/
Why would he do that? Did you check my command? With that command you can send message to all servers in an OU.
(Get-ADComputer -SearchBase "OU=Computers,DC=domain,DC=com" -Filter *).Name | Foreach-Object {Invoke-Command -ComputerName $_ {msg * "Your message"}}
Please remember to mark the replies as answers if they help.,
NEDIMMEHIC.ORGWhy do you think you need Invoke-Command. MSG remotes without that. It will just make the whole script much more prone t failure and assumes the user knows how t use PowerShell when it is clear that he doesn't.
It usually always best to use the simplest methods in scripting, programming or any technology.
\_(ツ)_/
Monday, October 9, 2017 7:34 AM -
Hi,
I agree with jrv when he said "simplest is often the best", but sometimes you have to do things more complex. In my case I couldn't use msg.exe method remoting for company reasons. But I can use powershell so you can still do this (I didn't copy the Get-ADcomputer ... jrv already did that):
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "C:\Windows\System32\msg.exe * 'you_message'"
Hope it helps. (I used it in a workflow and it works very well)
The key of learning is practice.
- Edited by arnaud.helin Monday, October 9, 2017 9:38 AM
Monday, October 9, 2017 9:20 AM -
It is not possible to block the MSG port as it is the SMB port. I don't think this is a case. Only Admins can use MSG. If the program was blocked it would not work with WMI or wit remoting so I doubt that it is disallowed.
\_(ツ)_/
Monday, October 9, 2017 9:26 AM -
You're right, but it is a political reason, not technical. We have to use Powershell if we want to make any remoting operation.
The key of learning is practice.
- Edited by arnaud.helin Monday, October 9, 2017 12:24 PM
Monday, October 9, 2017 12:23 PM -
I agree with you Arnaud and msg cannot be used in my example.Monday, October 9, 2017 12:58 PM