Solved

Powershell command to check exchange server health and send to me

Posted on 2013-05-10
3
1,078 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 43

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Read this checklist to learn more about the 15 things you should never include in an email signature.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video discusses moving either the default database or any database to a new volume.

749 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