5. Reporting with the Exchange Management Shell
The Exchange
Management Shell can actually be very effectively used for creating
reports. The EMS has quite a lot of powerful cmdlets, and with the
pipelining option it is possible to create all kinds of reporting. I'll
give you a few examples, although please bear in mind that the outputs
for many of these examples have been edited for readability.
The Get-ExchangeServer cmdlet will return a list of all Exchange 2010 servers in the organization:
[Edited for readability]
With the –Identity option it is
possible to retrieve the information for only one Exchange server, and
when the Get-ExchangeServer cmdlet is used in a pipeline with the
format-list command, all the detailed information for the server in
question is shown:
[Edited for readability]
If you want to retrieve mailbox information from your Exchange server, the Get-Mailbox and Get-MailboxStatistics cmdlets can be used:
[Edited for readability]
To get detailed information
about a particular mailbox, the output of that Mailbox's identity can be
piped to the Format-List command:
[Edited for readability]
The Get-MailboxStatistics cmdlet retrieves detailed information about Mailbox usage from an Exchange Server:
[Edited for readability]
So the Get-MailboxStatistics
cmdlet gives lots of information about usage. To get some real
reporting information, PowerShell has an option to convert its output to
HTML. So, when you enter the following command...
... nothing is logged to the
screen, but an HTML file is created in the directory where the
PowerShell is running. Use Internet Explorer to open the output file:
Using just the DisplayName is not really useful, so let's add some more parameters:
This will give the following HMTL file:
Much nicer!
NOTE
If you're enjoying pipelining, it's also possible to use the PowerShell Out-File option instead of redirecting using the ">".
Now let's create a small script with some variables:
$Now contains the date and time the script runs.
$BodyStyle contains a value used to retrieve a stylesheet to customize the HMTL file.
$MBXOutput contains the actual output from the Get-MailboxStatistics cmdlet.
Your script should look something like this:
Save this file as reporting.ps1
and run the script. It will still show the output of the query, but now
it'll be beautifully formatted according the CSS style sheet. This
methodology will allow you to create some really cool custom reporting
setups.