Solved

Powershell command to check exchange server health and send to me

Posted on 2013-05-10
3
1,034 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
Comment Utility
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 41

Accepted Solution

by:
Amit earned 500 total points
Comment Utility
0
 

Author Comment

by:Allanore
Comment Utility
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

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Join & Write a Comment

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.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
how to add IIS SMTP to handle application/Scanner relays into office 365.

743 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

16 Experts available now in Live!

Get 1:1 Help Now