Solved

Powershell command to check exchange server health and send to me

Posted on 2013-05-10
3
1,053 Views
Last Modified: 2013-05-16
Im trying to create an exchange powershell script to run these three following commands to check my exchange server status every so often.


Test-ServiceHealth servername | ft Role,RequiredServicesRunning -auto

test-mapiconnectivity -server "servername"

test-mailflow servername -targetemailaddress test@testaccount.com

What would be the easiest way to code this via powershell into a csv file and then send to me it as an attachment via email.
0
Comment
Question by:Allanore
3 Comments
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39156673
Export all your tests out to your csv/s using: cmdlet | export-csv [-append](you can only use append if you have powershell 3.0 installed).  Rather than export-csv though you might be better off using "out-file -append" as the data returned from the three separate cmdlets will be formatted differently.  To "export-csv -append" to the same file all the data's headers would need to be the same.

Then build your email using the following:
$msg = new-object Net.Mail.MailMessage
$msg.from = <from address>
$msg.subject = <subject>
$msg.body = <body>
$msg.to.add(<someone@email.com>)
$attachment = <path to attachment>
$msg.attachments.add($attachment)
$smtpServer = <SMTP server>
$smtp = new-object Net.Mail.SmtpClient($smtpServer, <port(25)>)
$smtp.Send($msg)

Open in new window

0
 
LVL 42

Accepted Solution

by:
Amit earned 500 total points
ID: 39156856
0
 

Author Comment

by:Allanore
ID: 39159756
For the health check report powershell script, how would i create a scheduled task to run this with my specific parameters in windows 2008 R2? Would i have to create a .bat file to launch the .ps1 script with the -server -sendmail parameters?
0

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
how to add IIS SMTP to handle application/Scanner relays into office 365.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now