Managing Exchange 2007 Mailbox Quotas with Windows PowerShell

The use of PowerShell with Exchange Server 2007 can do a great deal to ease the task of managing mailbox quotas. You can, for example, use scripts to customize quota messages, retrieve mailbox sizes, and set the quotas. Ben shows you how, in the 2nd installment of his Top Tips for SysAdmins.

Most Exchange organizations use mailbox quotas to help users manage the size of their mailbox and to keep storage utilization in check.  Managing quotas can be a burden on Exchange administrators, the help desk, and users, but with a few tweaks things can be made easier.

Exchange Mailbox Quota Types

Mailbox quotas can be set at the database or mailbox level.  Quotas set at the mailbox level will take precedence over database quotas.  Additionally, quotas can be a hard limit, preventing sending and/or receiving e-mail, or just a warning threshold which triggers a warning message.  It’s important to choose the right type of quotas to set – do you want users to be warned about their mailbox size, or do you want to prevent them from sending or receiving e-mail if they exceed their quota? The three mailbox quota types are:

Issue Warning Quota –

this is not a hard limit, but a warning threshold.  When it has been exceeded the user will get a warning message about their mailbox size, but will still be able to send and receive e-mail.

Prohibit Send Quota

this is a hard limit, and once a mailbox size exceeds it the user will no longer be able to send e-mail, but will still be able to receive e-mail.

Prohibit Send and Receive Quota –

this is also a hard limit, and once it is exceeded the user will no longer be able to send or receive e-mail messages.  Incoming e-mail will be returned to the sender.

Customizing Quota Messages

To make things easier for users, and to reduce the number of calls to the helpdesk, the messages which Exchange sends when a user is exceeding a quota limit can be customized to include more useful or practical information than the standard message gives.  Custom quota messages also support HTML, so you can include formatting or other HTML, such as link to a self-help knowledgebase article offering tips on reducing mailbox size.  In previous versions of Exchange modifying the quota messages was difficult and usually required programming skills, or custom DLL files, but with Exchange 2007 it can all be done with the PowerShell command line.

 

While there are only three mailbox quota types, there are four quota message types as a warning quota can be set with or without a hard limit quota.  Custom messages can be set for all four quota message types:

 

WarningMailboxUnlimitedSize –

 this message type is sent to mailboxes which have no size limit when the warning quota has been exceeded.

WarningMailbox –

this message type is sent to mailboxes which have a size limit (such as a Prohibit Send or Prohibit Send and Receive quota) when the warning quota has been exceeded.

ProhibitSendMailbox –

This message type is sent when the Prohibit Send storage quota is exceeded.

ProhibitSendReceiveMailBox –

This message type is sent when the Prohibit Send and Receive storage quota is exceeded.

 

The New-SystemMessage cmdlet is used to set a custom quota message:

 

 

This command will set an HTML custom message which includes a hyperlink:

 

 

Once a custom quota message has been set it can be viewed using the Get-SystemMessage cmdlet:

 

 

It can be modified using the Set-SystemMessage cmdlet:

 

 

And it can be removed using the Remove-SystemMessage cmdlet:

 

 

Quota messages are sent according to a schedule defined on each mailbox database.  The default schedule is daily, between 1am and 1.15am.  The schedule can be altered using the Set-MailboxDatabase cmdlet.

 

This command will set the database “Mailbox Database” on server “EXCHANEG01” to send quota notifications on Sundays and Wednesdays between 7am and 8am:

 

 

You must be delegated the Exchange Organization Administrator role to use the *-SystemMessage cmdlets.  You must be delegated the Exchange Server Administrator role and be a member of the local Administrators group for the target server to use the Set-MailboxDatabase cmdlet.

Retrieving Mailbox Sizes and Quotas

Mailbox sizes are retrieved using the Get-MailboxStatistics cmdlet.

 

 Mailbox Quotas are retrieved using the Get-Mailbox cmdlet.

 This simple script combines Get-MailboxStatistics with Get-Mailbox to show mailbox size and prohibit send quota in one command:

You must be delegated the Exchange View-Only Administrator role to use the Get-Mailbox and Get-MailboxStatistics cmdlets.

 Setting Mailbox Quotas

Mailbox quotas can be set in two places – directly on the mailbox or on the mailbox database.  By default Exchange 2007 sets a quota of 2000MB on all new mailbox databases, and all mailboxes in the database inherit this value.

 

The Set-MailboxDatabase cmdlet is used to set default quotas on a mailbox database using the PowerShell command line.

 

This command will set the default warning quota on the database “Mailbox Database” on server EXCHANGE01 to 975MB, and the limit at which users will no longer be able to send mail to 1000MB:

 

 

The Set-Mailbox cmdlet is used to set quotas on individual mailboxes.

 

This command will set the warning quota for user juser to 1475MB, and the limit at which the user will no longer be able to send mail to 1500MB.  It will also configure the mailbox not to use the database default quotas:

 

 

Quota increase requests will be fairly common for most organizations which use mailbox quotas.  Quota increases are usually governed by an IT policy, and increases are usually in fixed amounts.  This PowerShell script will automatically increment the quota size of a specified mailbox by a given amount. This script, or something like it, can be used to decrease the administrative overhead of mailbox quotas.  The script reads the current quota from the database or from the mailbox, shows what the existing quota is and what the new quota will be, then prompts for confirmation before setting the new quotas. It then displays confirmation that the new values have been set.  If the current quota is not a multiple of the increment specified it will be rounded up to the next increment, rather than having an increment added, which ensures that quotas are always a multiple of the desired increment value.

 

 

You must be delegated the Exchange Recipient Administrator role to use the Set-Mailbox cmdlet

Configuring the Mailbox Information Cache Refresh Interval

Exchange quota information is stored in Active Directory, and by default is cached by Exchange for up to two hours.  This means that it could take up to two hours for a quota change to take effect.  The recommended interval for Exchange to refresh quota information is 20 minutes, which can be set by adding three registry values.

 

Note – setting the cache refresh intervals too low can adversely affect the performance of Exchange.  Incorrectly editing the registry can cause serious problems that may require you to reinstall your operating system. Problems resulting from editing the registry incorrectly may not be able to be resolved.  Before editing the registry, back up any valuable data.  You need to be a local administrator on the Exchange server in order to edit the registry.

  1. Start the registry editor on your Exchange 2007 Mailbox server
  2. Locate the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeIS\ParametersSystem key.
  3. Create the “Reread Logon Quotas Interval” value
    1. Right-click ParametersSystem, select New, and then select DWORD value.
    2. Name the new DWORD value “Reread Logon Quotas Interval”.
    3. Right-click Reread Logon Quotas Interval, and then click Modify.
    4. Enter a decimal value of 1200 seconds (20 minutes)
  4. Create the “Mailbox Cache Age Limit” value
    1. Right-click ParametersSystem, select New, and then select DWORD value.
    2. Name the new DWORD value “Mailbox Cache Age Limit”.
    3. Right-click Mailbox Cache Age Limit, and then click Modify.
    4. Enter a decimal value of 20 (20 minutes)
  5. Locate the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchange ADAccess key.
  6. Create the “CacheTTLUser” value
    1. Right-click MSExchange ADAccess, select New, and then select Key.
    2. Name the new key Instance0.
    3. Right-click Instance0, select New, and then select DWORD value.
    4. Name the new DWORD value “CacheTTLUser”.
    5. Right-click CacheTTLUser, and then click Modify.
    6. Enter a decimal value of 300 (5 minutes)

 

Alternately, copy this text file and paste it into a file called MailboxCache.reg, then import it into the registry of each of your Exchange 2007 Mailbox servers

The Exchange Information Store service needs to be restarted for the change to become effective.  More information about these changes can be found on the Microsoft TechNet web site.

How you log in to Simple Talk has changed

We now use Redgate ID (RGID). If you already have an RGID, we’ll try to match it to your account. If not, we’ll create one for you and connect it.

This won’t sign you up to anything or add you to any mailing lists. You can see our full privacy policy here.

Continue

Simple Talk now uses Redgate ID

If you already have a Redgate ID (RGID), sign in using your existing RGID credentials. If not, you can create one on the next screen.

This won’t sign you up to anything or add you to any mailing lists. You can see our full privacy policy here.

Continue