#1 By: howtogeek, April 8th, 2013 10:27
Originally published at: http://www.howtogeek.com/141894/how-to-use-powershell-to-detect-logins-and-alert-through-email/
The Windows Task Scheduler can automatically send email at a specific time or in response to a specific event, but its integrated email feature won’t work very well for most users.
#2 By: Jerry Feth, April 9th, 2013 11:06
This is the title that made me finally take a look at the POWESHELL lessons, now I am going to have to find the time to actually dig in! In that I have not found that time as of yet, does anyone know how to attach the account that logged in to the alert used in this example?
#3 By: Lowell Heddings, April 9th, 2013 11:07
That's a good question, would be pretty useful on servers, I think.
I'm guessing that @taygibb can figure that out (he wrote the article).
#4 By: Taylor Gibb, April 9th, 2013 11:16
@geek that is a good point.
Its really simple too, just change the body parameter to: “$env:USERNAME Just Logged In”
#5 By: 2Noob2BTrue, April 10th, 2013 01:42
Yes that is all good but what happens when the user disconnects the PC from the internet before logging on? Will the email be sent next time that PC is connected to the net.?
#6 By: Taylor Gibb, April 10th, 2013 01:53
@2noob2bTrue Unfortunately not, the script will probably throw an exception, but this is a good point.
#7 By: Dave King, June 9th, 2013 02:05
@taygibb I am having problems getting this to work. this is the arguments i used minus the password for the email account
-Command “Send-MailMessage -From “email@example.com” -To “firstname.lastname@example.org” -Body “$env:USERNAME Just Logged In” -Subject “LOGIN” -SmtpServer “smtp.gmail.com” -Port 587 -Credential $(New-Object System.Management.Automation.PSCredential (email@example.com, $(ConvertTo-SecureString “PASSWORD” -AsPlainText -Force))) –UseSsl”
Task Scheduler has listed the task as being successfully run but i have not gotten an email. I am unsure what is wrong. Please help?
#8 By: Dave King, June 9th, 2013 02:42
SnapshotThis is a screenshot that i managed to get. i put the powershell and argument into a batch file and ran it and this is what came up. all i did was blank out the password