EMS has built-in reporting features that
use a variety of outputs. For example, the following cmdlet verifies
server functionality by logging on to the specified user’s mailbox and
reporting the latency:
Test-MapiConnectivity [email protected]
The output is presented on the display similar to the one shown in Figure 1.
Output
is normally sent to the display, but it can also be sent to files using
redirection. EMS has special cmdlets that also produce comma-separated
values (CSV), Extensible Markup Language (XML), and HTML output. These
types of output provide the flexibility that administrators need to
manipulate the data using familiar tools, such as Microsoft Excel.
1. Generating Largest Mail User Reports
The
following example uses PowerShell to list the top 25 largest mailboxes
on the specified server, the total number of mail items, and the size
of the mailbox. It sorts the list by descending size. The example uses
the standard Exchange WMI provider to access this information.
Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2
-ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size
| sort -descending "Size" | select-object -first 25
This
data might be useful for administrators to know who might need data
retention training. It might also be useful to demonstrate the need for
email archiving.
To make this script more portable, the output can be converted to HTML and redirected to a file, like this:
Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2
-ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size
| sort -descending "Size" | select-object -first 25 | ConvertTo-html
-title "Top 25 Largest Mailboxes on SERVER1" > "D:\Stats\25 Largest Mailboxes.html"
Improving it further, the output could be redirected to a unique filename, based on the system date:
Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2
-ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size
| sort -descending "Size" | select-object -first 25 | ConvertTo-html
-title "Top 25 Largest Mailboxes on SERVER1" > ("D:\Stats" + (get-Date).ToString("yyyyMMdd") + ".html")
Now, the cmdlet can be scheduled to run once per day, maintaining a separate report for each day.
Save the cmdlet in a .ps1 file as Top25LargestMailboxes.ps1. Because .ps1 files cannot be run directly from the Cmd.exe
prompt or by the Windows Task Scheduler, the administrator must run it
within the EMS/PowerShell environment. This is accomplished by using
the command PowerShell Top25LargestMailboxes.ps1. An
alternative is to create a batch file containing the same command and
run the batch file. The batch file can then be scheduled to run once
per day.
Tip
The
Top 25 Largest Mailboxes report could be published to the company’s
SharePoint “Wall of Shame.” Users will take measures to not make the
list.