DCSIMG
Mailbox Users Storage limit - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

Mailbox Users Storage limit

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

  
if(!$user.mDBUseDefaults)
   {
    
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

Comments

Jonathan Medd said:

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

# December 3, 2009 12:08 PM

ScriptFanatic said:

Thanks Jonathan, glad you find it usefull.

# December 3, 2009 1:25 PM

Dean said:

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

# August 3, 2010 3:53 PM

ScriptFanatic said:

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}

# August 3, 2010 4:31 PM

Dean said:

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?

# August 3, 2010 5:28 PM

ScriptFanatic said:

What's the value of $user?

# August 3, 2010 5:54 PM

Dean said:

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

# August 4, 2010 10:15 AM

Dean said:

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

# August 4, 2010 10:32 AM

ScriptFanatic said:

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

# August 4, 2010 10:46 AM

Dean said:

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?

# August 4, 2010 11:13 AM

ScriptFanatic said:

Dean,

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

# August 4, 2010 11:51 AM

Dean said:

Fantastic - that works a treat now.

Thanks again for all your help.

# August 4, 2010 12:24 PM

ScriptFanatic said:

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

# August 4, 2010 12:49 PM

Dean said:

Well, either way it's still impressive.

Thanks again

# August 4, 2010 1:00 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: