Exchange 2010-2013 Statistics with PowerShell

This template tracks the statistics of Exchange mailboxes and the mailbox databases of Exchange 2010 or 2013 server with the Mailbox role using PowerShell scripts.

Prerequisites:

  • PowerShell 2.0 must be enabled to establish a remote connection via an Exchange specific PowerShell web site end-point: $sess = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri "https://192.168.3.52/powershell" -Credential x13\Administrator -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -IdleTimeout 60000)
  • Exchange Management Tools must be installed on target Exchange server.
  • Windows Authentication should be enabled for PowerShell on the Exchange server. This can be configured in IIS mmc:
    Start > Administrative Tools > Internet Information Services (IIS) Manager.
  1. In the IIS console, expand Your Server, Sites, Default Web Site. Select the PowerShell application. On the central panel, open Authentication.
  2. Select Windows Authentication and Enable it from the right panel.

Credentials: The credentials must be that of an Exchange Administrator account (Organization Manager) with at least view-only permissions. Credentials should be provided with the domain part in the login field. For example – domain\user.

Note: If you have trouble with template functionality, refer to the troubleshooting section at the end of this document.


Monitored Components

Total mail size (MB)

This component monitor returns the total mail size on the server in MB.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer


Total mailboxes
This component monitor returns the total number of mailboxes on the server.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer


Total items in mailboxes
This component monitor returns the total number of emails on the server.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer

Note for Exchange 2013 users: If this monitor is not working correctly, refer to the following Microsoft article that outlines a known issue with this monitor: http://support.microsoft.com/kb/2795291/en-us.


Total size of specified database file (MB)

This component monitor returns the total size of all mailboxes in the specified database in MB.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Database_name

where:
database_name – target mailbox database name;


Example:

Mailbox Database

To see the names of your mailbox databases, run the following command in the Exchange Management Shell: Get-MailboxDatabase


Total mailboxes in specified database file

This component monitor returns the number of mailboxes in the specified database.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Database_name

where:
database_name – target mailbox database name;


Example:

Mailbox Database

To see the names of your mailbox databases, run the following command in the Exchange Management Shell: Get-MailboxDatabase


Items in mailbox of specified user

This component monitor returns the number of emails for the specified user.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

user_name

where:
user_name – target username;


Example:

john

To see the names of your mailbox databases, run the following command in the Exchange Management Shell: Get-Mailbox


Mailbox size of specified user (MB)

This component monitor returns the mailbox size for the specified user in MB.

Note: You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

user_name

where:
user_name – target username;


Example:

john

To see the names of your mailbox databases, run the following command in the Exchange Management Shell: Get-Mailbox


Average items per mailbox
This component monitor returns the average number of emails per mailbox based on a mathematical count.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer


Size of largest user mailbox (MB)
This component monitor returns the size of the largest mailbox. You can see the user name for the assigned mailbox in the message field.

Note: You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer


Dismounted mailbox databases
This component monitor returns the number of dismounted mailbox databases. Dismounted databases are displayed in the message field.

The name of the last dismounted database is taken from the list of databases and is not based on the actual time the database was dismounted. There is no database attribute that records the time it was dismounted.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer


Mounted mailbox databases
This component monitor returns the number of mounted mailbox databases. Mounted databases are displayed in the message field.


Note:
You must specify the correct arguments in the Script Arguments field of the corresponding PowerShell Monitor. If you fail to do this, the counter will return with an error of "Undefined" status. This monitor requires the following argument:

Server_name

where:
server_name – hostname or FQDN of target Exchange server;


Example:

xchng2010

To see the names of your Exchange servers, run the following command in the Exchange Management Shell: Get-ExchangeServer


Troubleshooting

If you have a returned error similar to the following:

Message: ERROR: Please check target server argument and credentials (should be domain\user). [192.168.1.206] Connecting to remote server failed with the following error message : Access is denied.

Resolution: This error could occur when you use the wrong credentials. Check the credentials and verify the credentials are in the following format: (domain\user). The user should be Exchange Organization Manager.


If you have a returned error similar to the following:

ERROR: The operation couldn't be performed because object 'Mailbox Database 10580933221\*' couldn't be found on 'xchng2010.apmteam.sw'.

Resolution: Provide the correct database name.

If you have a returned error similar to the following:

[192.168.1.206] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. The WinRM client tried to use Negotiate authentication mechanism, but the destination computer (192.168.1.206:443) returned an 'access denied' error. Change the configuration to allow Negotiate authentication mechanism to be used or specify one of the authentication mechanisms supported by the server. To use Kerberos, specify the local computer name as the remote destination. Also verify that the client computer and the destination computer are joined to a domain. To use Basic, specify the local computer name as the remote destination, specify Basic authentication and provide user name and password.

Resolution: This error indicates that Windows Authentication is not enabled for the PowerShell application on IIS on the Exchange server.


If you have a returned error similar to the following:

[192.168.1.206] Connecting to remote server failed with the following error message : The WinRM client received an HTTP status code of 403 from the remote WS-Management service.

Resolution: If you get this error, you should check your SSL settings for the PowerShell application in IIS on the Exchange server.

You should use one of the following configurations:
- Require SSL unchecked;
- Require SSL checked and Client Certificates is set to Accept;
- Require SSL checked and Client Certificates is set to Ignore;


If you have a returned error similar to the following:

Message: ERROR: Please check target server argument and credentials (should be domain\user). [xchng2010] Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. This user allowed a maximum number of 5 concurrent shells, which has been exceeded. Close existing shells or raise the quota for this user.

Resolution: This error could occur when you use more than five remote PowerShell sessions (set by default) at the same time. If you get this error, it is recommended that you increase the number of concurrent shells on the Exchange server. Open a windows Command Line as Administrator and run the following command:
winrm set winrm/config/winrs @{MaxShellsPerUser="30"}

Portions of this document are provided courtesy of the following sources: