CloudServus - Microsoft Consulting Blog

Generating HTML Web Reports through Exchange Management Shell - Microsoft Consulting Services - CloudServus - United States

Written by cloudservuscom | May 14, 2009 11:34:22 AM

 

As you know Exchange Management Shell is an extension of Windows PowerShell (PS). Today I found a really useful PS command to generate HTML reports that include data generated through Exchange Management Shell commands. In an effort to create a “Dashboard” for our Exchange environment, I’ve been trying to find a way to gather information in Exchange Shell and publish that data into an HTML report. The ConvertTo-HTML command will do exactly that.

The PS command is called ConvertTo-HTML. For more details on the command itself, please refer to the MS Technet article. In this article I am going to jump right into some reports I’ve created for myself.

http://technet.microsoft.com/en-us/library/dd347572.aspx

 

Generate a Web Report for Number of Mailboxes Per Database on a Server:

Get-Mailbox -server <servername> | Group-Object -Property:Database | Select-Object Name,Count | sort Name | ConvertTo-HTML –title “Number of Mailboxes Per Database: EXCHSRVR1” -Property DisplayName, ItemCount –pre “Produced by Dave Rowe” –post “Contact Dave for Questions” > C:tempMailboxesPerDB.htm

The output of this command produces a list of all DBs on the specified Exchange server (ex: EXCHSRVR1) and the total number of mailboxes per database. Then it sorts the output by Name (of the database) and converts it to an HTML page.

 

As you can see the formatting of the output is not great. You have to use some complex scripting to clean it up. Here is a sample of one I did just to add some space in the first column.

Get-Mailbox -server <SERVERS> | Group-Object -Property:Database | Select-Object Name,Count | sort Name | ConvertTo-HTML –title “Number of Mailboxes Per Database: EXCHSRVR1” -Property Name, Count | foreach {if($_ -like “*<tr><td>*”){$_ -replace “<tr><td>”, “<tr><td width=400>”}else{$_}} > C:tempMailboxesPerDB.htm

This script uses a foreach loop to find all “<tr><td>” tags and replace them with “<tr><td width=300>”. It’s a lot of complex code for a simple change, but makes the report much easier to read.