Notification when someone login locally or remotely to the server

Math Tec
Math Tec used Ask the Experts™
on
Hi,

We have windows server 2008R2. Is there any way that the server sends an email with login details (IP address, location,...etc) when someone login locally or remotely to the server? Or is there any application can do that if this is not doable in server features?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
Commented:
It's a way with a script something like this

https://gallery.technet.microsoft.com/scriptcenter/Get-LogonLogoff-Times-and-3acf7d62

Here's something similar...
And not, is not doable using server features

And it should be configured on the Active Directory GPO object in the Login/Login scripts feature


param($computer="127.0.0.1",$outputfile="C:\loginevents.csv",[switch]$writetoxml,$userName) 

$IP =(Test-Connection -ComputerName $computer -Count 1  | Select -ExpandProperty IPV4Address | select -ExpandProperty IPAddressToString)

if ($userName -eq $null) { 
    $userName=$env:username.toString() 
} 
 
$loginAllArray=@() 
$loginUserArray=@() 
 
$logoffAllArray=@() 
$xmlUserArray=@() 
$restartReg 
 
#Function to query the remote computer 
Function queryComputer($computer) { 
    $restartReg = $false 
 
    ping -n 1 $computer | out-null 
 
    if ($? -eq $false) { 
        echo "Computer not online. Quitting" 
        exit 
    } 
} 
 
queryComputer($computer)

Open in new window

Sending an email whenever someone logs in will require some heave scripting. You can; however, use the Get-EventLog cmdlet to return  all login and logoff events for the server. Here is a guide on how to do this:
How to check event logs with PowerShell

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