MartinRouterKing Posted March 8, 2016 Posted March 8, 2016 Hi All, Without going into detail is there anyway I can create a login script so that when a certain user logs in it will send me an email? Also is there anything I can run to keep an audit of what people access when they login in terms of folders and documents? Thanks in advance. Kind Regards
Ralph1337 Posted March 9, 2016 Posted March 9, 2016 (edited) Email? Not that i can think of.. Create a file in a certain location? which is time / date stamped for each time they log on? More than likely, but is a script the right way to do it?.. or maybe some helpful tools?: Cjwdev | AD Tidy Free Tools __ Just noticed your name. HA! Edited March 9, 2016 by Ralph1337
Steve21 Posted March 9, 2016 Posted March 9, 2016 Const ADMIN_EMAIL = "MYEMAIL" Const SMTP_SERVER = "SMTPSERVER" Const SMTP_PORT = 25 Const SMTP_SSL = False Const ENABLE_DEBUGGING = False Set WshNetwork = CreateObject("WScript.Network") Set objSysInfo = CreateObject("ADSystemInfo") set objShell = WScript.CreateObject("WScript.Shell") strUser = objSysInfo.UserName Set objUser = GetObject("LDAP://" & strUser) dteTime = Time dteDate = Date strMessage = "A user has logged onto " & ComputerName & " with the following details: " _ & "Logon Date: " & dteDate & " " _ & "Logon Time: " & dteTime & " " _ & "Account Name: " & AccountName & " " result = SendMail(strMessage) If ENABLE_DEBUGGING Then WScript.Echo result WScript.Quit Function AccountName If IsNull(WshNetwork) Then Set WshNetwork = CreateObject("WScript.Network") AccountName = WshNetwork.UserName End Function Function ComputerName If IsNull(WshNetwork) Then Set WshNetwork = CreateObject("WScript.Network") ComputerName = WshNetwork.ComputerName End Function Function SendMail(strBody) Set objEmail = CreateObject("CDO.Message") With objEmail .From = ADMIN_EMAIL .To = ADMIN_EMAIL .Subject = "Logon Notification - " & AccountName .HTMLBody = strBody .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTP_PORT If SMTP_SSL Then .Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True End If .Configuration.Fields.Update On Error Resume Next Err.Clear .Send If Err.number <> 0 Then SendMail = Err.Description Else SendMail = "The server did not return any errors." End If On Error Goto 0 End With End Function As above, we use it for tracking when certain accounts logon and just have it going to a duff email box A user has logged onto XYZ with the following details: Logon Date: 15/01/2016 Logon Time: 15:05:11 Account Name: XYZ Steve
zoohead Posted March 9, 2016 Posted March 9, 2016 (edited) Hi Martin The following is a .vbs script that I found online a couple of years ago. I put it in the login script in a new gpo. Created a secutity group for the gpo and add the user to that group. Option Explicit Dim objEmail Dim mbAnswer Dim attFName Dim oShell Dim user Dim comp Set oShell = CreateObject( "WScript.Shell" ) user=oShell.ExpandEnvironmentStrings("%UserName%") comp=oShell.ExpandEnvironmentStrings("%ComputerName%") ' Create the message object using CDO Set objEmail = CreateObject("CDO.Message") ' The address you want to be sending from - probably the pupil monitoring group objEmail.From = "put the student's email address here" ' The address you want to be sending to - the pupil monitoring group objEmail.To = "put your email address here" ' The text to appear in the subject of the email objEmail.Subject = "Student Monitoring Network Logon" ' The text body of the message. Currently shows which user has logged in to which machine no. objEmail.Textbody = "User " & user & " Has Logged in to machine no " & comp ' change the myexchservername to the network name of your exch server. objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "put your mail server details here" ' Assign additional message properties, update the object, and send the message objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send Works like a charm for us. Ian Edited March 9, 2016 by zoohead
HPlum78 Posted March 9, 2016 Posted March 9, 2016 (edited) $PSEmailServer = 'your.mailserver.co.uk' $strDate=Get-Date-Formatdd-MM-yy-HH_mm_ss Send-MailMessage -To '[email protected]' -From '[email protected]' -Subject "The following user" $env:USERNAME "has logged on to" $env:COMPUTERNAME -Body "The following user" $env:USERNAME "has logged on to" $env:COMPUTERNAME "@" $strDate something like the above in powershell. Edited March 9, 2016 by HPlum78
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now