Solved

Powershell command to check exchange server health and send to me

Posted on 2013-05-10
3
1,103 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In-place Upgrading Dirsync to Azure AD Connect
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

707 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