Av rating:
Total votes: 3
Total comments: 0


Ben Lye
Managing Exchange 2007 Mailbox Quotas with Windows PowerShell
24 November 2008

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:

 

New-SystemMessage -QuotaMessageType WarningMailbox -Language EN -Text "My custom quota message."

 

 

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

 

 New-SystemMessage -QuotaMessageType WarningMailbox -Language EN -Text "

You are approaching the maximum size of your mailbox.

Please see this article for details on how to reduce your mailbox size: http://intranet.example.com/kb/mailboxsize.html

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

 

Get-SystemMessage -Identity EN\WarningMailbox | Format-List

 

It can be modified using the Set-SystemMessage cmdlet:

 

Set-SystemMessage -Identity EN\WarningMailbox -Text "My modified custom quota message."

 

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

 

Remove-SystemMessage -Identity EN\WarningMailbox

 

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:

 

Set-MailboxDatabase -Identity "EXCHANGE01\Mailbox Database" -QuotaNotificationSchedule "Sun.7:00-Sun.8:00","Wed.7:00-Wed.8:00"

 

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.

 

Get-MailboxStatistics juser | fl TotalItemSize

 Mailbox Quotas are retrieved using the Get-Mailbox cmdlet.

Get-Mailbox juser | fl *Quota

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

# Get-MailboxQuota.ps1

# Script for showing mailbox size and quota

 

# Exit the script if username is not found

If ($args[0] -eq $null) {

      Write-Host "Error: No user specified" -ForegroundColor "Red"

      break

}

 

# Get the username from the command line argument

$username = $args[0]

 

# Get the mailbox, break if it's not found

$mb = Get-Mailbox $username -ErrorAction Stop

 

# Get the mailbox statistics

$mbstats = Get-MailboxStatistics $username

 

# If the mailbox is using the database quotas then read them, otherwise read them from the mailbox

If ($mb.UseDatabaseQuotaDefaults -eq $true) {

      $quota = (Get-MailboxDatabase -Identity $mb.Database).ProhibitSendQuota.Value.ToMB()

} else {

      $quota = $mb.ProhibitSendQuota.Value.ToMB()

}

 

# Get the mailbox size and convert it from bytes to megabytes

$size = $mbstats.TotalItemSize.Value.ToMB()

 

# Write the output

Write-Host "Mailbox:   " $mb.DisplayName

Write-Host "Size (MB): " $size

Write-Host "Quota (MB):" $quota

Write-Host "Percent:   " ($size/$quota*100)

Write-Host

 

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:

 

Set-MailboxDatabase “EXCHANGE01\Mailbox Database” -IssueWarningQuota 975MB -ProhibitSendQuota 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:

 

Set-Mailbox juser -IssueWarningQuota 1475MB -ProhibitSendQuota 1500MB –UseDatabaseQuotaDefaults $false

 

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.

 

# Increase-MailboxQuota.ps1

# Script for incrementing mailbox quotas

 

# Amount to increase prohibit send quota by in megabytes

$QuotaIncrement = 250

 

# Amount to subtract from prohibit send quota to set warning quota

$WarningDifference = 25

 

# Get the username from the arguments

$username = $args[0]

 

# Prompt if no location was passed

if (-not $username) {

      $username = Read-Host "Username"

}

 

# Get the mailbox

$Mailbox = Get-Mailbox -Identity $username -ErrorAction Silentlycontinue

 

# Error if the mailbox wasn't found

If (-not $mailbox) {

      Write-Host "User not found" -Foregroundcolor:Red

      break

}

 

# Get the mailbox information and size

$DisplayName = $Mailbox.DisplayName

$Database = $Mailbox.Database

$UsingDBQuotas = $Mailbox.UseDatabaseQuotaDefaults

$MailboxSize = (Get-MailboxStatistics -Identity $Mailbox.Name).TotalItemSize.value.ToMB()

 

 

# Get the current quota values

if ($UsingDBQuotas -eq $True)

      {

            # Database quotas are being used so read them from the DB

            $Database = Get-MailboxDatabase -Identity $Database

            $ProhibitSendQuota = $Database.ProhibitSendQuota.value.ToMB()

            $IssueWarningQuota = $Database.IssueWarningQuota.value.ToMB()

      }

else

      {

            # Mailbox quotas are being used so read them from the mailbox

            $ProhibitSendQuota = $Mailbox.ProhibitSendQuota.value.ToMB()

            $IssueWarningQuota = $Mailbox.IssueWarningQuota.value.ToMB()

      }

 

# Calculate the new prohibit send quota

If (($ProhibitSendQuota % $QuotaIncrement) -eq 0) {

      # Existing quota is a multiple of $QuotaIncrement so increase it by $QuotaIncrement

      $NewProhibitSendQuota = $ProhibitSendQuota + $QuotaIncrement

} Else {

      # Existing quota is not a multiple of $QuotaIncrement so round it up to nearest multiple of $QuotaIncrement

      $NewProhibitSendQuota = $ProhibitSendQuota + ($QuotaIncrement - ($ProhibitSendQuota % $QuotaIncrement))

}

 

# Calculate the new warning value

$NewIssueWarningQuota = $NewProhibitSendQuota - $WarningDifference

 

# Show what we're going to do

Write-Host ""

Write-Host "Full Name:           ", $DisplayName

Write-Host "Database:            ", $Database

Write-Host "Using Default Quota: ", $UsingDBQuotas

Write-Host ""

Write-Host "Mailbox Size (MB):   ", $MailboxSize, "MB"

Write-Host ""

Write-Host "Current Quota:       ", $ProhibitSendQuota, "MB"

Write-Host "Current Warning:     ", $IssueWarningQuota, "MB"

Write-Host ""

Write-Host "New Quota:           ", $NewProhibitSendQuota, "MB"

Write-Host "New Warning:         ", $NewIssueWarningQuota, "MB"

Write-Host ""

$Continue = Read-Host "Continue [Y/N]?"

 

# Ask if we want to continue

Switch ($Continue) {

      "Y" {$Continue = $True}

      "y" {$Continue = $True}

}

 

# Stop here if not continuing

If ($Continue -ne $True) {

      break

}

 

# Set the new values on the mailbox

$NewProhibitSendQuota = [STRING]$NewProhibitSendQuota + "MB"

$NewIssueWarningQuota = [STRING]$NewIssueWarningQuota + "MB"

Set-Mailbox -Identity $Mailbox -UseDatabaseQuotaDefaults $False -ProhibitSendQuota $NewProhibitSendQuota -IssueWarningQuota $NewIssueWarningQuota

 

# Update the mailbox quota information

$Mailbox = Get-Mailbox $Mailbox

$ProhibitSendQuota = $Mailbox.ProhibitSendQuota.value.ToMB()

$IssueWarningQuota = $Mailbox.IssueWarningQuota.value.ToMB()

 

# Write some output to confirm the new values

Write-Host ""

Write-Host "Updated Quota:       ", $ProhibitSendQuota, "MB"

Write-Host "Updated Warning:     ", $IssueWarningQuota, "MB"

Write-Host ""

 

 

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


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeIS\ParametersSystem]

"Reread Logon Quotas Interval"

=dword:000004b0

"Mailbox Cache Age Limit"

=dword:00000014

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchange ADAccess\Instance0]

"CacheTTLUser"

=dword:0000012cc

 

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 - .



This article has been viewed 2345 times.
Ben Lye

Author profile: Ben Lye

Ben Lye is a senior systems administrator at a multi-national software company. He has over 10 years experience supporting and administering Windows and Exchange, and has been MCSE and MCP certified since 1999. Ben is passionate about automating and streamlining routine tasks, and enjoys creating and using tools which make day-to-day administration easier.

Search for other articles by Ben Lye

Rate this article:   Avg rating: from a total of 3 votes.


Poor

OK

Good

Great

Must read
 
Have Your Say
Do you have an opinion on this article? Then add your comment below:
You must be logged in to post to this forum

Click here to log in.
 

Hunting in Packs, Seamless-ness and Happy Holidays
 I attended DevConnections (Exchange) last month and was blown away by the technical talks. Speakers... Read more...

The Road to Beta - Exchange Server Archiver speaks!
 Richard, Robert and Marine at Red Gate Software talk about designing, developing and testing Exchange... Read more...

Exchange Server Archiver, Las Vegas, Lemons and Whales
 It’s the fall and the leaves are falling all around us. And so are the barriers to Exchange Archiving. Read more...

Reporting on Mobile Device Activity Using Exchange 2007 ActiveSync Logs
 In this new column giving practical advice on all things Sys Admin related, Ben Lye takes on the often... Read more...

Asking for help – come and talk to us!
 “When you buy something from a self-assembly furniture shop, do you read the instructions?” This was... Read more...

Using Exchange 2007 for Resource Booking
 The process of booking various resources to go with a meeting room just got a whole lot easier with... Read more...

Free Exchange Server eBook
 Simple-Talk has teamed up with Sybex to give you a free copy of "Best of Exchange Server 2007" Read more...

High Availability in Exchange 2007
 Neil Hobson writes about the ways that MS Exchange 2007 can ensure that your organisations messaging... Read more...

Message Hygiene in Exchange Server 2007
 Around four out of every five email messages are spam. Now that the nuisance threatens to engulf what... Read more...

Controlling Email Messages using Exchange's Transport Rules
 Some tasks that should have been easy in previous versions of Exchange just weren't. Now, with... Read more...

Over 150,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.

Join Simple Talk