Sending mail with PowerShell

[June 27, 2014] Update: I’ve made several updates, including multiple recipients and sending attachments.

If you’ve created a PowerShell script that runs as a scheduled task, you may want to have it send you an e-mail with a log file or other notification about what the script did or didn’t do (i.e. error notification). PowerShell version 2 provides the Send-MailMessage cmdlet to do this, but in some cases the older System.Net.Mail .NET namespace is a more desirable approach (System.Net.Mail also works in PowerShell version 1).
Continue reading “Sending mail with PowerShell”