Running test-servicehealth from Excel list


I have a list of 20 Exchange 2007 servers in Excel that are going to be rebooted this evening.

I would like to run test-servicehealth and test-mapiconnectivity against them tomorrow morning. Rather than typing each one out manually, I'd like Powershell to be able to grab them from the Excel sheet and run through each one.

Does anyone know how I would do this?
Who is Participating?
soostibiConnect With a Mentor Commented:
The test-servicehealth cmdlet has a -server parameter, so you can use the following structure to make the test from any Exchange box or workstation that has the Exchange Management Tools installed. I recommend to put the serverlist into a TXT file or a CSV. Reading directly from an XLS is more complicated.

get-content c:\serverlist.txt | foreach-object {test-servicehealth -server $_}

Of course you can customize the test-searvicehealth part accourding to your needs.

The test-mapiconnectivity requires databases or mailboxes as an input to test:

get-content c:\databases.txt | foreach-object {test-mapiconnectivity -database $_}
get-content c:\mailboxestotest.txt | foreach-object {test-mapiconnectivity -identity $_}

Of course, here you have to customize the rest of the test-mapiconnectivity part accourding to your needs.
bruce_77Author Commented:
That's great, thanks very much.

For this: get-content c:\serverlist.txt | foreach-object {test-servicehealth -server $_}

I can see the servers and the results of test-servicehealth, but is there any way to return the name of the servers too, so if there is a failure on one I know which one it is?
Unfortunately I have only Exchange 2010, so I can not check, if the result will be OK for Exchange 2007, but here is my try:

get-content c:\serverlist.txt | foreach-object {$s = $_; test-servicehealth -server $s | select-object -property *, @{n="Server";e={$s}}}

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

You can direct feed the Exchange servers without the server with the below command.
Get-ExchangeServer | Test-ServiceHealth

Would have to check how we get the name of the servers though....this will only give you the role of the server.

- Habz
bruce_77Author Commented:
Thanks both

As regards this line here:

get-content c:\serverlist.txt | foreach-object {$s = $_; test-servicehealth -server $s | select-object -property *, @{n="Server";e={$s}}}

Isn't there an easier way to get the name of the server than this? Surely a get-server somewhere in there would work?
Check if the output of
test-servicehealth -server $s | fl *

includes any line, with the servername in it. If not, there is no easier way to do. (In Exchange 2010 the servrename is there.)
bruce_77Author Commented:
Sorry- where should I enter this?
All Courses

From novice to tech pro — start learning today.