Create Exchange 2010 Server Reports with PowerShell

My recent articles have focused on reporting on mailbox usage in Microsoft Exchange 2010 with PowerShell (see: Create Exchange 2010 Mailbox Size Reports with PowerShell, as well as creating individual inbox reports and multiple inbox reports). But you might also want to prepare reports on the Exchange 2010 server itself. I believe there are several items that merit your attention. Some of these areas will require the Exchange Management Console. Others can be done from any administrator desktop with RPC and/or WMI access. But they all can be accomplished using PowerShell.

Service Reports

On one hand, getting the status of Exchange-related services is very easy and doesn’t require anything other than a PowerShell prompt, admin credentials, and RPC connectivity to the Exchange server.

PS C:\> $ex = "chi-ex01"
PS C:\> get-service -DisplayName "Microsoft Exchange*" -ComputerName $ex

I defined a variable for my Exchange server to save some typing. The result of this command can be seen below.
exchange 2010 server
At a glance it is easy to see which services stopped. The downside is that we can’t tell which services are disabled, which is why they aren’t running. But this is fast and it may be all you need. Otherwise, we’ll turn to WMI.

PS C:\> Get-WmiObject win32_service -filter "displayname Like 'Microsoft Exchange%'" -ComputerName $ex | Sort State | Select name,StartMode,State

Now, as you can see in Figure 2, I can identify potential problem services, i.e. those that are configured to auto start but are not running.
exchange 2010 server

Disk Usage Reports

Next, I would want to make sure there is plenty of disk space on my Exchange server. Again, WMI is the best solution here. Here’s a one line expression that I think will get you what you need.

Get-WmiObject win32_logicaldisk -filter "drivetype=3" -ComputerName $ex |
Select SystemName,Name,@{Name="SizeGB";Expression={[int]($_.Size/1GB)}},
@{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,4)}},
@{Name="PerFree";Expression={[int](($_.freespace/$_.size)*100)}},
VolumeDirty

When used in a PowerShell session, you get a result as in Figure 3.
Exchange 2010 server
I’ve formatted the size values in GB to make the result more meaningful. I‘ll want to watch that percent free value — I’ll have to take some action if it keeps dropping.

Database File Reports

But overall disk usage is only part of the picture. I should take a look at the Exchange database and log files. Using the Exchange management console I can get all the mailbox databases on my server.

[PS] C:\>$db = get-mailboxdatabase

The database object has properties for the file items I’m interested in.

[PS] C:\>$db | Select Name,EDBFilePath,LogFolderpath | format-list

You can see my result below.
Exchange 2010 server
However, I can’t simply run Get-ChildItem on that path because I’m running this from my client desktop and the path is relative to the server. I hate to have to log onto servers, so I’ll have to do a little PowerShell voodoo to get the database and log files using traditional PowerShell remoting.

[PS] C:\>invoke-command {Param($item) dir $item} -ComputerName chi-ex01 -ArgumentList $db[0].EDBFilePath

The image below illustrates what kind of results I can expect.
Exchange 2010 server
With this, I can build a little PowerShell command to use in the Exchange management console to get database and log information.

$db | Select Name,EDBFilePath,
@{Name="EDBSizeMB";Expression={
$r = invoke-command {Param($item) dir $item} -ComputerName $_.Server.name -ArgumentList $_.EDBFilePath [math]::Round($r.Length/1MB,2)}},
LogFolderpath,
@{Name="LogFolderSizeMB";Expression={
$r = invoke-command {Param($item) dir $item | measure length -sum} -ComputerName $_.Server.name -ArgumentList $_.LogFolderPath
[math]::Round($r.sum/1MB,2)
}}

This is definitely something you would want to drop in a script or function. I’m creating some custom properties for the file and folder sizes uses my remoting command. As you can see below, I probably have some overdue maintenance to do.
Exchange 2010 server
These are just a few server-related items you may wish to report on. For example, there is an entire library of performance counter information you may want to query. As with my mailbox reporting, I’ve been displaying formatted results to the screen, but you may elect to create HTML reports, Word documents, or archive to an XML file. PowerShell gives you options – sometimes the hardest task is deciding.