Mailbox Users Storage limit

August 30, 2009

My morning task today includes the following: get all mailboxes (Exchange 2003) larger than X megs where the associated user mailbox storage limits are overriding the settings of the Mailbox store.

Storage limit information for user accounts is available in Active Directory Users and Computers on the user ‘Exchange General’ tab (click on ‘Storage Limits’ at the bottom). The ‘Storage Limits’ dialog box specifies the mailbox storage limits for warning or prohibiting a mailbox-enabled user from sending or receiving email. You can also use this dialog box to specify the number of days a deleted item is stored in the mailbox store before it is permanently deleted but for my task it is not needed.

So the script goes as follows:

  • Use WMI Get all mailboxes larger than 250MB in size.

  • Get the associated mailbox user from AD using Quest AD cmdlets.

  • Filter those which override the mailbox store policy (the checkbox, (1) in the figure above is not checked). The LDAP attribute name for the checkbox is mDBUseDefaults and the value is FALSE.

  • In addition, extend the filtered mailbox objects with storage limit attributes (and values):
    – Issue warning at (KB) – Ldap name (2) is mDBStorageQuota.
    – Prohibit send at (KB) – Ldap name (3) is mDBOverQuotaLimit.
    – Prohibit send and receive at (KB) – Ldap name (4) is mDBOverHardQuotaLimit.

$Server = ExchangeServer
$MbxSize= 250MB

Get-WMIObject Exchange_Mailbox -Namespace root\MicrosoftExchangeV2 -Computer $server -Filter size>=$($MbxSize/1kb) | Foreach-Object {

$IncludedProperties = mDBUseDefaults,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit
$user = Get-QADUser $_.LegacyDN -IncludedProperties $IncludedProperties

Add-member -InputObject $_ NoteProperty mDBUseDefaults $user.mDBUseDefaults
Add-member InputObject $_ NoteProperty mDBStorageQuota $user.mDBStorageQuota
Add-member InputObject $_ NoteProperty mDBOverQuotaLimit $user.mDBOverQuotaLimit
Add-member InputObject $_ NoteProperty mDBOverHardQuotaLimit $user.mDBOverHardQuotaLimit –PassThru

} |
Select-Object MailboxDisplayName,Size,mDBUseDefaults,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



  1. Jonathan MeddDecember 3, 2009 ב 12:08

    Nice post, just what I was looking for. As always, thanks for sharing!

  2. ScriptFanaticDecember 3, 2009 ב 13:25

    Thanks Jonathan, glad you find it usefull.

  3. DeanAugust 3, 2010 ב 15:53

    Hi Shey

    This is very useful – thanks for sharing. Quick question though – how easy would it be to modify this to read in the current mailbox size and then perform a calculation to update the quota values on the fly.

    So far, I have been able to read the mailbox size, but I am struggling as to how to make the calculations and updates.

    Basically, I’ve been tasked to help a colleague tidy his Exchange 2003 environment, which currently has no mailbox limits in place. Before we apply a policy, we need to filter out a number of accounts that will be over the limits we want to set.

    What we want to do is run a PS script that will:
    – read in the mailbox size
    – calculate a waning limit (size + 90mb)
    – calculate a send limit (size = 95mb)
    – calculate a receive limit (size = 100mb)
    – apply these settings

    Of course, not forgetting to flick the use defaults switch as we go.

    Any help would be greatly

  4. ScriptFanaticAugust 3, 2010 ב 16:31

    Try this against a test user:

    $MailboxDisplayName = ‘John Doe’

    # get the mailbox
    $mbx = Get-Wmiobject Exchange_Mailbox -namespace root\MicrosoftExchangeV2 -Computer ServerName -filter “MailboxDisplayName=’$MailboxDisplayName'”

    # get the user object from AD
    $user = Get-QADUser $mbx.LegacyDN

    # get the mailbox size in bytes
    $mbxByteSize = $mbx.size*1kb

    # calculate limits
    [int64]$mDBStorageQuota = ($mbxByteSize + 90mb)/1kb # Issue warning at (KB)
    [int64]$mDBOverQuotaLimit = ($mbxByteSize + 95mb)/1kb # Prohibit send at (KB)
    [int64]$mDBOverHardQuotaLimit = ($mbxByteSize + 100mb)/1kb # Prohibit send and receive at (KB)
    $mDBUseDefaults = $false

    # apply settings
    $user | Set-QADUser -ObjectAttributes @{mDBStorageQuota=$mDBStorageQuota;mDBOverQuotaLimit=$mDBOverQuotaLimit;mDBOverHardQuotaLimit=$mDBOverHardQuotaLimit;mDBUseDefaults=$mDBUseDefaults}

  5. DeanAugust 3, 2010 ב 17:28

    Hi Shey

    Thanks for this, and for the speed in your reply.

    The scripts seems to work OK, right upto the point where it atempts to wright the values. I get this error:

    Set-QADUser : Exception has been thrown by the target of an invocation.
    At C:\Temp\Shey.ps1:19 char:20 + $user | Set-QADUser <<<< -ObjectAttributes @{mDBStorageQuota=$mDBStorageQuota;mDBOverQuotaLim DBOverHardQuotaLimit=$mDBOverHardQuotaLimit;mDBUseDefaults=$mDBUseDefaults} Any ideas?

  6. ScriptFanaticAugust 3, 2010 ב 17:54

    What’s the value of $user?

  7. DeanAugust 4, 2010 ב 10:15

    Hi Shey

    The display name of of mailbox is “test mailbox”, looking in ADSI – the legacyDN is “test.mailbox”

    What I’m not sure about, is how to get PS to show me what its reading in, when its setting the $ variables. Yeah, I know its going to be something simple 🙂

    Thanks for your help so far – you brought me a long way already. Thanks

  8. DeanAugust 4, 2010 ב 10:32

    Update – I was having a dumb moment. I have managed to find the values…. $user is:

    [PS] C:\Temp>$user

    Name Type DN
    —- —- —
    Test Mailbox user CN=Test Mailbox,CN=Users,DC=kmh,DC=nhs,DC=uk

  9. ScriptFanaticAugust 4, 2010 ב 10:46

    So, $user contains a valid user account and you still get that error?

  10. DeanAugust 4, 2010 ב 11:13

    Hi Shey

    Yes, it contains a valid user that I created for this test.

    If I type $mbx, I get the details of the account, and as you see, if I type $user – I get the name, type and DN. Should I not be seeing the LegacyDN here?

  11. ScriptFanaticAugust 4, 2010 ב 11:51


    Replace all occurrences of [int64] with [int] and try again.

  12. DeanAugust 4, 2010 ב 12:24

    Fantastic – that works a treat now.

    Thanks again for all your help.

  13. ScriptFanaticAugust 4, 2010 ב 12:49

    Cool, this means I should have test it before posting!

  14. DeanAugust 4, 2010 ב 13:00

    Well, either way it’s still impressive.

    Thanks again