This content is part of the Essential Guide: The essential guide to PowerShell in Exchange
Manage Learn to apply best practices and optimize your operations.

How to generate HTML reports with the Exchange Management Shell (EMS)

Use Exchange Management Shell commands to extract Exchange 2007 mailbox statistics from the server and display them in HTML format in Internet Explorer.

The Exchange Management Shell (EMS) in Exchange Server 2007 can generate valuable administrative reports. However, this involves cumbersome commands and generates a report that isn't universally usable. In this tip, Brien Posey details how to extract mailbox data and export it into an HTML-formatted report using the EMS.

Exchange Server 2007 administrators can use the Exchange Management Shell (EMS) to extract valuable data from the server. Although this can be useful, there are a couple of problems with using the Exchange Management Shell as a reporting tool.

First, the commands that you must use can be cumbersome and complicated to implement. Second, output typically is written to the screen in text-only format, which isn't helpful for anyone else.

The Exchange Management Shell can be used to create reports in various formats. Here's a way to create an HTML report detailing the number of items in each Exchange mailbox that's readable in Internet Explorer (IE).

More on Exchange Server reporting:
ADVSoft MailDetective: Monitoring, statistics and analysis for Exchange Server

Free log reporting tool for HTTP and Exchange Server

The Exchange Management Shell can produce robust reports in file formats that aren't proprietary to Exchange Server. Unfortunately, administrators still must use complex commands to create these. Once you understand how to use these commands, you can build them into a script so you don't have to enter them manually the next time you need to generate a report.

There are several ways to create reports, including using the Get-Mailbox Statistics command. This command also works with the Get-Mailbox command or any other Get commands within the EMS. However, a basic technique that doesn't involve the use of complicated commands is:

Get-MailboxStatistics | Select DisplayName, ItemCount | Sort ItemCount

This command is actually three different commands in one. It basically acquires all Exchange mailbox statistics, filters everything except for display names and item counts, and then sorts remaining data according to item count. Results of this command are shown in Figure 1.

Create reports using the Exchange Management Shell in Exchange Server 2007 Figure 1. Results of the Get-MailboxStatistics | Select DisplayName, ItemCount | Sort ItemCount command.

We have created a report containing information about how many items each user has in his mailbox. Unfortunately, this report can't be sent to anyone else. Therefore, we must convert this report into HTML format that can be viewed using Internet Explorer (IE).

To do so, begin with the same basic command, but append the ConvertTo-HTML command. We'll also specify the properties that we have already extracted from Exchange using the Get-MailboxStatistics command. Finally, we must use the redirect command (>) and specify a filename to which the report should be outputted. The full command syntax is:

Get-MailboxStatistics | Select DisplayName, ItemCount | Sort ItemCount | ConvertTo-HTML –Property DisplayName, ItemCount >C:\temp\items.htm

When you execute this command, it doesn't seem to do anything. However, it creates the file: C:\Temp\Items.htm.

When you open Windows Explorer and double-click on the file, it will open IE and display a report similar to that shown in Figure 2.

an HTML report generated through the Exchange Management Shell Figure 2. The converted report is in HTML format.

If you don't want to use Windows Explorer to open your report, you can open it from the Exchange Management Shell. To do so, enter:

Invoke-Item C:\Temp\Items.htm

Although this command launches IE and opens your report, you can't append this command to the end of the previous command. Fortunately, if you're building a script, you can include this as a separate command within the script.

About the author: Brien M. Posey, MCSE, has previously received Microsoft's MVP award for Microsoft Exchange, Windows Server and Internet Information Server (IIS). He has served as CIO for a nationwide chain of hospitals and was once responsible for the Department of Information Management at Fort Knox. As a freelance technical writer, Brien has written for Microsoft, TechTarget, CNET, ZDNet, MSD2D, Relevant Technologies and other technology companies. You can visit Brien's personal website at

Do you have comments on this tip? Let us know.

Please let others know how useful this tip was via the rating scale below. Do you know a helpful Exchange Server, Microsoft Outlook or SharePoint tip, timesaver or workaround? Email the editors to talk about writing for

Dig Deeper on Exchange Server setup and troubleshooting

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.