Send archives - Network Administrator Knowledgebase

Network Administrator Knowledgebase:

send

Jun 27 2008   10:56PM GMT

Send a Message to All Users in an OU



Posted by: Michael Khanin
Microsoft Windows, send, message, Command line

By using the DSQUERY command and “Net Send” we can send a message to all users in a given OU.
It’s really simple, create a script, name it NetSendOU.bat and use the following syntax:

NetSendOU OU Message

Where OU is the organizational unit, like “OU=Users,DC=AdminInfo,DC=Ca”, and Message is the message text, like “Hello from AdminInfo.ca”.

NetSendOU.bat contains:
@echo off
if {%2}=={} @echo Syntax: NetSendOU OU “Message”&exit /b 1
setlocal
set query=dsquery user %1 -o samid
set message=%2
for /f %%u in (’%query%’) do (net send “%%u” %message%)
endlocal
exit /b 0