Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes you want to write an email to all users that are currently in the office. You could now just insert all the email addresses into a mail but you might not know who's in the office your you forget someone.

Another solution would it be to write the email to a security group. But this will also sent the mail to users that are on vacation.

I know that you can see the sessions on a fileserver as well as the opened files. Can I use this information to get all the users that are currently logged in? And how could I open a mail with all those users filled into the "to" field of a mail (maybe with some kind of batch file)?

share|improve this question
What's wrong with sending the email to all users, whether they're logged in or not? – joeqwerty Sep 9 '10 at 11:55
I don't want to send a mail to 50 users if only 5 are in the office. And it is also annoying if someone returns from vacation and has many mails that are out of date. It will also not waste space at the exchange data store. – 2ndkauboy Sep 9 '10 at 11:57
Exchange leverages Single-Instance storage on the mailbox stores. A single email duplicated out to all staff residing in a single mailbox store will only occupy a single message worth of space. In 2007 and 2010 that only applies to attachments, but the text portion of an email usually trivial. – Chris Thorpe Sep 9 '10 at 12:00
You wouldn't waste space in the exchange store. - edit : You beat me to it by 5 seconds Chris! :) – Bryan Sep 9 '10 at 12:00
It seems like a lot of effort to deal with a situation that is so inconsequential, IMO. If you're really worried about it why not invest in a corporate instant messaging solution? – joeqwerty Sep 9 '10 at 12:04

You would have to poll every workstation and server in your environment for the current logged-in-user, and from there, pull the email address from each AD User object. I would recommend scripting this solution.

But then again, this is a lot of wasted effort when sending to the Everyone group is not that much inconvenience.

share|improve this answer
...and even then, what about people who have locked their computer prior to leaving instead of logging out? I like the corporate IM solution joeqwerty suggested above. – EEAA Sep 9 '10 at 12:18
It must not be bullet proof. Just some little help for the many non-technical users that do not know how to write to a group or how to use an IM. And with the IM solution you might have the problem, that some users might have switched it off. But they can't switch off email completely (except of not opening Outlook the whole day). – 2ndkauboy Sep 9 '10 at 12:24
Can you provide me a resource on how to get that information. I am not a full time administrator, so some useful tutorials about getting data from the AD would be nice. – 2ndkauboy Sep 9 '10 at 12:26
Thanks for pointing out the IM mention above. I +1'd it. – gWaldo Sep 9 '10 at 12:40
@Kau-Boy, The Microsoft Technet Script Center Repository is . The search feature is reasonably good. I must say, however, that if you don't have the requisite knowledge of how to code already (which I highly encourage), I really do recommend a broadcast email. The time you'll spend getting proficient will far outweigh the combined deleting of messages... – gWaldo Sep 9 '10 at 12:43

This is quite easy. AD has a 'lastloggedontimestamp'.

I use the Quest AD CmdLets still, but you could re-jig this to work with the standard ActiveDirectory module.

Basically you get 'today' and then scan for anyone with the last logontimestemp that matches today.

$today = (Get-Date).day
get-qaduser | where { $ -eq $today } | select samaccountname, lastlogontimestamp, Email

Its not perfect, and I can think of improvements but it fits your requirements

share|improve this answer
I want to give you points, but I don't want to up-vote this as an answer. So I'm just commenting that I love this solution. It's not that terrible to script this out in powershell. – Get-HomeByFiveOClock Dec 29 '14 at 20:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.