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 (see Figure 1):
Test-MapiConnectivity amy@companyabc.com
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.
Generating User
Distribution Reports
Reports that
list user mailbox distribution across all mailbox stores can be helpful
to know if the user load is balanced in the organization. The following .ps1 example shows how to produce a report listing the
total number of mailbox stores, the number of mailboxes in each store,
and the total number of mailboxes.
This .ps1
script contains comments, variables, and error trapping. Comments begin
with the “#” symbol and are useful for administrators to understand what
the script or cmdlet is doing and are ignored by EMS/PowerShell.
Variables always start with the $ symbol and are used to assign values
or collections. Error trapping handles exceptions or errors that can
occur in the script so that the script continues to run:
#Get all mailbox stores in the organization and assign them to the $MailboxDatabases array variable
$MailboxDatabases = get-mailboxdatabase
write-host "There are" $MailboxDatabases.Count "Mailbox Stores in the organization."
write-host ("-"*70)
#Get each database and assign it to the $Database array variable
ForEach ($Database in $MailboxDatabases) {
#Derive the Mailbox server name from the database
$MailboxServer = $Database.server.name
#Derive the database name from the database
$DatabaseName = $Database.name
#Assign the full database name to the $FullDatabaseName variable
$FullDatabaseName = "$MailboxServer" + "\" + "$DatabaseName"
#Count the number of databases on the server
$count=0
get-mailboxdatabase –server $MailboxServer | ForEach-Object {$count++}
#Get the mailboxes for this database
If ($count –gt 1) {
$mailbox = get-mailbox -database $FullDatabaseName
}
Else {
$mailbox = get-mailbox -database $DatabaseName
}
write-host "There are" $mailbox.Count.toString("#,#") "mailboxes in" $FullDatabaseName
#The trap statement traps the NullException error which occurs when a database has no mailboxes
trap{
write-host "There are no mailboxes in" $FullDatabaseName;
continue
}
}
write-host ("-"*70)
#Get all mailboxes in the organization
$mailboxes = get-Mailbox
write-host "The total number of mailboxes in the organization is" $mailboxes.count.tostring("#,#")
Working with Event
Logs
Exchange Server administrators often work with
Windows event logs to troubleshoot issues. Because EMS runs in the
PowerShell environment, the administrator can take advantage of
PowerShell’s Get-Eventlog cmdlet to work with event logs.
This example displays
all events in the Application Event Log in which the source begins with
the word “Exchange.” The output is exported to a CSV file for easy
manipulation in Microsoft Excel:
get-eventlog Application | where {$_.Source -ilike "Exchange*"} | export-csv c:\events.csv