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.
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?
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).
@geek that is a good point.
Its really simple too, just change the body parameter to: “$env:USERNAME Just Logged In”
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.?
@2noob2bTrue Unfortunately not, the script will probably throw an exception, but this is a good point.
@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?
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
This topic is now closed. New replies are no longer allowed.