powershell-logo

This might seem like such a simple command to be ecstatic about, that is unless you’ve ever tried to script emailing log files.

Oh it’s doable.  There’s vbScripts that do it.    They just, well… they’re ‘wordy’

They’re not horribly complex to be honest, but it seemed to me at the time there had to be an easier way.  Since the vbScripts themselves weren’t exactly in ‘English’

But now There is

Powershell V2’s new “SEND-MAILMESSAGE

The Syntax of the command is a little eye popping as it any piece of software at the command level.

Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] -BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]

 

But really, it’s very easy.  

 

SEND-MAILMESSAGE –to johnqsmith@contoso.com –subject ‘BackupLogs’ –from backup@contoso.com SmtpServer 10.0.0.10

 

There you’ve sent a simple mail message of nothing from one line.  And read it.  You don’t have to be a developer to understand what that means!

SEND an eMAILMESSAGE to johnqsmith@contoso.com from backup@contoso.com with a SUBJECT of ‘BackupLogs’ to the SMTP Server which was 10.0.0.10

And if you need to tuck in an attachment like those backup logs, just plug in the –attachment parameter with the location of the file in question.

 

SEND-MAILMESSAGE –to johnqsmith@contoso.com –subject ‘BackupLogs’ –from backup@contoso.com SmtpServer 10.0.0.10 –attachment ‘C:BackupLogLogfile.log’

 

That’s the beauty of this, a command that just makes dead simple sense.  So there you have it, Powershell the nicest “MAIL”man you’ve ever met

Sean
The Energized Tech