Last update: Version 1.02, November 21st, 2014.
Those leveraging quota settings to manage their Exchange environments, you are probably periodically running some sort of script or set of cmdlets to retrieve information on mailbox sizes, quota settings and if any mailbox is above any of the quota thresholds. For a quick indication of the current size in relation to the quota settings, StorageLimitStatus may contain one of the following indicators depending on the quota settings on the mailbox or mailbox database hosting the mailbox:
- BelowLimit – Speaks for itself
- IssueWarning – Mailbox size above Issue Warning limit
- ProhibitSend – Mailbox size above Prohibit Send limit
- NoChecking – No quota checking
- MailboxDisabled – Mailbox size above Prohibit Send and Receive quota limit
So, to get a list of all mailboxes with any over-quota status, you can use:
Get-MailboxDatabase | Get-MailboxStatistics | Where {$_.StorageLimitStatus -match 'IssueWarning|ProhibitSend|MailboxDisabled'} | Select DisplayName, ItemCount, TotalItemSize, StorageLimitStatus, LastLogonTime
Unfortunately, in Exchange 2013 the StorageLimitStatus gets no longer populated:
As KB2819389 explains, this is by design. In Exchange 2013, mailbox quotas are no longer cached. By not being cached, retrieving quota information may result in poor performance as it queries Active Directory for quota related attributes. The argument is a bit puzzling, considering there is a NoADLookup switch which directs the cmdlet to retrieve information from the mailbox database (cache) instead of Active Directory. Perhaps a better workaround would have been to make NoADLookup a parameter, make it $true by default and leave StorageLimitStatus unpopulated when NoADLookup is $true.
Of course, that does not help customers who want a quick quota report. For this purpose I have created two things in 1 script:
- A helper function Get-StorageLimitStatus() which will take a mailbox statistics object and return a StorageLimitStatus object.
- A script Get-MyMailboxStatistics.ps1, a proxy function for Get-MailboxStatistics which will use the Get-StorageLimitStatus helper function to populate the StorageLimitStatus.
Get-StorageLimitStatus
When you want to use the helper function, extract it and include it in your quota reporting script or PowerShell profile (making it available when firing up a shell). To use the helper function in the cmdlet shown earlier, use:
Get-MailboxDatabase | Get-MailboxStatistics | Select -ExcludeProperty StorageLimitStatus DisplayName, ItemCount, TotalItemSize, @{n="StorageLimitStatus"; e={ Get-StorageLimitStatus $_}}, LastLogonTime | Where {$_.StorageLimitStatus -match 'IssueWarning|ProhibitSend|MailboxDisabled'}
This will remove StorageLimitStatus from the output and add a calculated field bearing the same the name, calling the Get-StorageLimitStatus helper function with the current mailbox statistics object to set its value.
Get-MyMailboxStatistics.ps1
This is a proxy function for the Exchange Management Shell cmdlet Get-MailboxStatistics. This means that the current, original cmdlet was used to create a wrapper which will call the original cmdlet. Having a wrapper allows you to restrict or enhance the original cmdlet and tailor it to your needs.
A quick tip on how to create a proxy script in the clipboard (more information on creating proxy commands here):
$data= New-Object System.Management.Automation.CommandMetaData (Get-Command Get-MailboxStatistics) [System.Management.Automation.ProxyCommand]::create($data) | clip.exe
Downside is that future changes to the Get-MailboxStatistics cmdlet will not be automatically incorporated in the wrapper. Feeding it objects also doesn’t work, but you can work around that by temporary storing the objects in a variable and passing that to the script (see examples below).
To populate the StorageLimitStatus, we will post-process each object in the output of Get-MailboxStatistics, using Add-Member to overwrite (-Force) its current value and –PassThru to pass it along in the pipeline. Being a proxy command, the parameter options are identical to the original Get-MailboxStatistics. Some examples:
.\Get-MailboxStatistics.ps1 -Database MDB2
$m= Get-Mailbox –Database MDB2 $m | .\Get-MailboxStatistics.ps1 | ft –AutoSize DisplayName,TotalItemSize,StorageLimitStatus
Do be aware that this will incur Active Directory queries and thus performance of the script may not seem fast. However, in previous versions of Exchange you got immediate results as all the quota information was readily available from the cache. On the plus side, the status you see will be non-cached, current information.
On a final note and maybe needless to say that in order to use this you need to run it from the Exchange Management Shell and since it’s an unsigned script you need to set ExecutionPolicy to Unrestricted.
Feedback
Feedback is welcomed through the comments. If you got scripting suggestions or questions, do not hesitate using the contact form.
Download
You can download the script from the TechNet Gallery here.
Revision History
See Technet Gallery page.
Pingback: Get-MyMailboxStatistics | JC's Blog-O-Gibberish
Pingback: Weekly IT Newsletter – May 19-23, 2014 | Just a Lync Guy
Pingback: NeWay Technologies – Weekly Newsletter #96 – May 22, 2014 | NeWay
Pingback: NeWay Technologies – Weekly Newsletter #96 – May 23, 2014 | NeWay
Awesome script,
some suggestions, have it so that it can run as a powershell module,
also from working with many users the script does not seem to function too well, I get a “The session availability is busy” line 121
LikeLike
Pingback: Exchange 2016 skupiny, mĂstnosti, Back Pressure, sdĂlenĂ© schránky – ITmix.cz