howtogeek — 2013-04-08T10:27:02-04:00 — #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 — 2013-04-09T11:06:42-04:00 — #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 — 2013-04-09T11:07:47-04:00 — #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 — 2013-04-09T11:16:56-04:00 — #4
@geek that is a good point.
Its really simple too, just change the body parameter to: “$env:USERNAME Just Logged In”
2noob2btrue — 2013-04-10T01:42:42-04:00 — #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 — 2013-04-10T01:53:05-04:00 — #6
@2noob2bTrue Unfortunately not, the script will probably throw an exception, but this is a good point.
kingjnrdavida — 2013-06-09T02:05:50-04:00 — #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 “firstname.lastname@example.org” -To “email@example.com” -Body “$env:USERNAME Just Logged In” -Subject “LOGIN” -SmtpServer “smtp.gmail.com” -Port 587 -Credential $(New-Object System.Management.Automation.PSCredential (firstname.lastname@example.org, $(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 — 2013-06-09T02:42:52-04:00 — #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 — 2014-07-11T14:26:32-04:00 — #9
This topic is now closed. New replies are no longer allowed.