Record and send email when a user logs on to a server using a Domain Admin account

Carl Billington
Carl Billington used Ask the Experts™
on
Is it possible to send an email notification when a user logs on using a Domain Admin account? Or at the very least record the name, computer and date/time stamp and email this information a specific email address at the end of the week?
   
The environment consists of Windows 2003-2012 RS servers.
 
Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Yep, pretty easy.

Just assign a login script in ADUC, and have it do whatever. A common config is to just append username and time to a text file on the network.
echo Log In %Date% %TIME% %USERNAME% >> \\someserver\someshare\logins.txt

Should do it. Maybe add some commas if you plan to throw into an Excel spreadsheet.

You can also assign a logoff script, appending the same file, or a separate one.

Author

Commented:
But this will log all user logons. I only want to record Domain Admins. I do not need to record Network Administrators etc.
 
Let me know your thoughts.
Only assign the script to accounts you would like to monitor.
It's a matter of determining if the user is in the Administrators role as part of the login script.

$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'System.Security.Principal.WindowsPrincipal' $windowsIdentity

if ($windowsPrincipal.IsInRole("Administrators"))
{
    # Put your email logic here.
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial