howtogeek at April 8th, 2013 10:27 — #1
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.
pacs_geek at April 9th, 2013 11:06 — #2
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?
geek at April 9th, 2013 11:07 — #3
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).
taygibb at April 9th, 2013 11:16 — #4
@geek that is a good point.
Its really simple too, just change the body parameter to: “$env:USERNAME Just Logged In”
2noob2btrue at April 10th, 2013 01:42 — #5
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.?
taygibb at April 10th, 2013 01:53 — #6
@2noob2bTrue Unfortunately not, the script will probably throw an exception, but this is a good point.
kingjnrdavida at June 9th, 2013 02:05 — #7
@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?
kingjnrdavida at June 9th, 2013 02:42 — #8
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
geek at July 11th, 2014 14:26 — #9
This topic is now closed. New replies are no longer allowed.