Tuesday, 14 May 2013

How to send a file as email using Shell Command

Normally we used to generate lot of report using Exchange Management Shell and moving output from exchange server to you desktop is little bit tough, where we used to Map the drives and transfer the files to bring the data to our system from Server.

Using Send-MailMessage option in Exchange Management Shell, we can easily send the file as attachment to our email address and below the shell command to send emails
$file = "C:\ScriptOutput.csv"


Send-MailMessage -Attachments $file -To rajkumar.mcitp@outlook.com -From Admin@DomainName.Com -Subject Test -SmtpServer yourexchangeservername.domainname.com

I normally use these shell command to send the Message Tracking Logs csv file as emails to my mailbox.