This script gets the following Exchange database statistics :
- Server name
- Database name
- The last full backup
- The number of mailboxes
- The database size
- The average mailbox size
- The database whitespace
Script :
function Get-DatabaseStatistics { $Databases = Get-MailboxDatabase -Status foreach($Database in $Databases) { $DBSize = $Database.DatabaseSize $MBCount = @(Get-MailboxStatistics -Database $Database.Name).Count $MBAvg = Get-MailboxStatistics -Database $Database.Name | %{$_.TotalItemSize.value.ToMb()} | Measure-Object -Average New-Object PSObject -Property @{ Server = $Database.Server.Name DatabaseName = $Database.Name LastFullBackup = $Database.LastFullBackup MailboxCount = $MBCount "DatabaseSize (GB)" = $DBSize.ToGB() "AverageMailboxSize (MB)" = $MBAvg.Average "WhiteSpace (MB)" = $Database.AvailableNewMailboxSpace.ToMb() } } } Get-DatabaseStatistics|Out-GridView
My Powershell script categories
- Active Directory
- Cluster
- Database
- Exchange
- Files and folders
- Hardware
- Network
- Operating System
- PKI
- SCCM
- Service and process
- Tips
- VMWare
Reference
Get-MailboxStatistics
This cmdlet is available in on-premises Exchange Server 2013 and in the cloud-based service. Some parameters and settings may be exclusive to one environment or the other.
Use the Get-MailboxStatistics cmdlet to obtain information about a mailbox, such as the size of the mailbox, the number of messages it contains, and the last time it was accessed. In addition, you can get the move history or a move report of a completed move request.
Detailed Description
On Mailbox servers only, you can use the Get-MailboxStatistics cmdlet without parameters. In this case, the cmdlet returns the statistics for all mailboxes on all databases on the local server.
Note:
The Get-MailboxStatistics cmdlet requires at least one of the following parameters to complete successfully: Server, Database, or Identity.
You can use the Get-MailboxStatistics cmdlet to return detailed move history and a move report for completed move requests to troubleshoot a move request. To view the move history, you must pass this cmdlet as an object. Move histories are retained in the mailbox database and are numbered incrementally, and the last executed move request is always numbered 0. For more information, see “EXAMPLE 7,” “EXAMPLE 8,” and “EXAMPLE 9” in this topic.
Note:
You can only see move reports and move history for completed move requests.
You need to be assigned permissions before you can run this cmdlet. Although all parameters for this cmdlet are listed in this topic, you may not have access to some parameters if they’re not included in the permissions assigned to you.
Parameters
Parameter | Required | Type | Description | ||
---|---|---|---|---|---|
Database | Required | Microsoft.Exchange.Configuration.Tasks.DatabaseIdParameter | This parameter is available only in on-premises Exchange 2013.
The Database parameter specifies the name of the mailbox database. When you specify a value for the Database parameter, the Exchange Management Shell returns statistics for all the mailboxes on the database specified. You can use the following values:
This parameter accepts pipeline input from the Get-MailboxDatabase cmdlet. |
||
Identity | Required | Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter | The Identity parameter specifies a mailbox. When you specify a value for the Identity parameter, the command looks up the mailbox specified in theIdentity parameter, connects to the server where the mailbox resides, and returns the statistics for the mailbox.
This parameter accepts the following values:
|
||
Server | Required | Microsoft.Exchange.Configuration.Tasks.ServerIdParameter | This parameter is available only in on-premises Exchange 2013.
The Server parameter specifies the server from which you want to obtain mailbox statistics. You can use one of the following values:
When you specify a value for the Server parameter, the command returns statistics for all the mailboxes on all the databases, including recovery databases, on the specified server. If you don’t specify this parameter, the command returns logon statistics for the local server. |
||
Archive | Optional | System.Management.Automation.SwitchParameter | The Archive switch parameter specifies whether to return mailbox statistics for the archive mailbox associated with the specified mailbox.
You don’t have to specify a value with this parameter. |
||
DomainController | Optional | Microsoft.Exchange.Data.Fqdn | This parameter is available only in on-premises Exchange 2013.
The DomainController parameter specifies the fully qualified domain name (FQDN) of the domain controller that retrieves data from Active Directory. |
||
Filter | Optional | System.String | This parameter is available only in on-premises Exchange 2013.
The Filter parameter specifies a filter to filter the results of the Get-MailboxStatistics cmdlet. For example, to display all disconnected mailboxes on a specific mailbox database, use the following syntax for this parameter: -Filter ‘DisconnectDate -ne $null’ |
||
IncludeMoveHistory | Optional | System.Management.Automation.SwitchParameter | The IncludeMoveHistory switch specifies whether to return additional information about the mailbox that includes the history of a completed move request, such as status, flags, target database, bad items, start times, end times, duration that the move request was in various stages, and failure codes. | ||
IncludeMoveReport | Optional | System.Management.Automation.SwitchParameter | The IncludeMoveReport switch specifies whether to return a verbose detailed move report for a completed move request, such as server connections and move stages.
|
||
NoADLookup | Optional | System.Management.Automation.SwitchParameter | This parameter is available only in on-premises Exchange 2013.
The NoADLookup switch specifies that information is retrieved from the mailbox database, and not from Active Directory. This helps improve cmdlet performance when querying a mailbox database that contains a large number of mailboxes. |
||
StoreMailboxIdentity | Optional | Microsoft.Exchange.Configuration.Tasks.StoreMailboxIdParameter | This parameter is available only in on-premises Exchange 2013.
The StoreMailboxIdentity parameter specifies the mailbox identity when used with the Database parameter to return statistics for a single mailbox on the specified database. You can use one of the following values:
Use this syntax to retrieve information about disconnected mailboxes, which don’t have a corresponding Active Directory object or that has a corresponding Active Directory object that doesn’t point to the disconnected mailbox in the mailbox database. |