Wednesday 30 July 2014

Send an email in Powershell

Below is a very basic Powershell script which can be used to send an email. Not super difficult to figure out how this works but can be useful for adding into a scheduled task or as part of remediation script:

$email = @{
 From = look_out@dinosaurs.com
 To = staff@dinosaurs.com
 Subject = "Danger - Incoming Asteroid"
 SMTPServer = "mailserver.domainname"
 Body = "Danger! Incoming asteroid. Everyone to the escape pods"
 }

send-mailmessage @email


NB it's worth mentioning that you need to put the email addresses in quotation marks.

No comments:

Post a Comment