Monday, May 18, 2015

Be alerted of upcoming full executive mailboxes


It is a good idea to keep mailbox size limits on your on-premises Exchange Servers for a few reasons:

- Preventing "mail storms" from running your databases storage out of disk space.
- Being able to control the maximum desired size of the mailbox databases.
- No mailbox limit means that nothing is get deleted and the Exchange becomes a document storage.

However, there are always those important management users that you don't want to allow them to run out of mailbox space.
A full mailbox in those cases may mean that a very important Email will not be received and your job will be on the line (and no one will care that the executive assistant disregarded all of those mailbox storage space warning messages even weeks before the mailbox clogged up).

So what can be done ?
Create a script to notify you of those mailboxes that are about to run out of space !The script that can be run daily will give you the option to either enlarge the mailbox or notify the user to archive or delete unneeded Emails.
Do not wait for the last moment as changing a mailbox size can take up to 2 hours go into effect:
Mailbox Size Limits Are Not Enforced in a Reasonable Period of Time


Here are the steps to make your notification script:

1. Set specific per-mailbox quota for executive mailboxes.
First, set up a mailbox quota for each user, letting go of the default database quota settings.
Keep those setting alive... but configure specific mailbox limit for each one of those mailboxes because you know that when the time comes you will need to change it anyway.

2. Set a way to distinguish between executive and none executive user mailboxes.
In order for the script to notify you about executive users only, you should set up a way to distinguish between executive and non-executive mailboxes.
One way (that I use in the script) is to gather all executive mailboxes into specific database / databases.
Another way is to assign a specific value in AD for executive users which you could query to gather all the executive mailboxes from all the Exchange databases.

for example:
$VIPList = get-mailboxdatabase *vip* | get-mailbox -ResultSize unlimited
Gets all mailboxes located on databases who's name contains the word VIP
Note ! My script uses this method so make sure to modify the script if needed !!! 

$VIPList = get-mailbox -ResultSize unlimited | where {$_.CustomAttribute10 -like "Executive"}
Gets all mailboxes with the value "Executive" in CustomAttribute10.

Of course you can use any desired attribute and any desired value to distinguish the executive mailboxes.

3. Select who will be notified
You may be the one who makes the decisions what actions to take when the reports arrive, or you may want your Help Desk to handle this task, so you need to decide who's Email the script will use (you can always assign multiple Email addresses).

4. Which SMTP server to use in order to route the mail
Nothing special here. You need an SMTP server (hub transport or other) to sent the notification Email.

Download the script here

The script assumes the executive databases are named with VIP in the database name.
You MUST change to your own search convention as stated above.
Also change the following parameters:

$SMTPServer = "192.168.1.2"
$ReportExceedingPrecentage = "94"
$ReportSender = "ExchangeServer@Mydomain.com"
$ReportRecipients = "HelpDesk@Mydomain.com","Me@Mydomain.com"

$SavedReportFilePath = "C:\LargeVIPMailboxes-$date.html"

Keep the $date.html at the end so the file will be saved with the date of creation.

This is how the report should look.
Just make sure to schedule the script for a daily run.
For assistance with creating a batch file for scheduling see my article




Thursday, May 7, 2015

Using the Exchange 2010 Anti-Spam feature to block specific IP addresses

The Exchange anti-spam features allow for a verity of options for protecting the Exchange environment.
Those features can be implemented for the Edge transport server or even on the Hub transport servers.

My article will focus on installing the Anti-Spam features on the Hub transport servers and on a script I wrote to automate adding / removing / viewing the IP addresses that are configured to be blocked by the IP Block List.

The reason I found for this is that in a large environment you may find that many servers are configured to be allowed connection and even relay using the Exchange Hub Transport SMTP service.
At times you may find that one of those servers go bad and starts sending a lot of Emails and even flood your Exchange server due to a software bug, or even if you would like to block a connection coming from the Internet (in case your Exchange server is getting its Emails directly).

If you got a single Hub Transport server you could easily do this configuration manually, however if you are using multiple hub transport servers and would like to configure the block list using a single commend the script may be helpful.

Lets begin...

Installing the Anti-Spam functionality
To start using those options you need to install them on the Transport/Edge Exchange server.
The installation is done using the built in .\install-AntispamAgents.ps1 script located on every Exchange server at  %system drive%/Program Files\Microsoft\Exchange Server\V14\Scripts folder

After installation the transport service needs to be restarted with the command
Restart-Service MSExchangeTransport or by using the services console.

For more information on installing this component see
Enable Anti-Spam Functionality on a Hub Transport Server


By default all of the Anti-Spam features are enabled at the Organization level in the management console, however they are not configured.









I chose to disable the features I did not want to run.

The Next step will be to install the Anti-Spam feature on every Hub Transport server you want.

It should be noted that every Hub Transport server can be configured differently altogether so you should decide if to install the feature and where.

The provided script makes an assumption that all Hub Transport servers in the organization will use the same IP blocking settings, so you may need to modify the script for your own environment.

Next we will take a look at how to configure the feature manually using the management console.
Navigate to the Server Configuration section, select a Hub Transport server where you installed the features and you will see the Anti-Spam tab.




















When we select Properties we are able to add or remove a specific IP address, Subnet or range of IP addresses.




You can also see that it is possible to define if the blocking will never expire or set this blocking to expire at a specific date and time.

I would not recommend using complete network subnets or IP address ranges unless you are sure that there is no scenario there there will need to unblock a specific address from the range or subnet.

You can add an IP address manually to check how this feature work, for example by adding your workstation IP address and then using Telnet command to perform an SMTP Email transaction with the server.



The result above will be seen by the sending party.
In case this is a real mail server with mailboxes, the sender will get this message as an NDR.

However since the SMTP session will be disconnected right after the "Mail From" section, this messaging transaction will not be logged or found in the Exchange tracking logs. The server owner should be informed that you configured the IP to be blocked since if the server is using an application to send Emails and those will fail to be routed the only way to discover why will be by using Telnet from the sending server to the HT server and seeing this error message.

Now that we know what is expected to happen lets continue to the automation section.
Copy the following script into a new text file using notepad and save as IPBlockListScript.ps1

#####
Add-PSSnapin microsoft.exchange.management.powershell.e2010 -ErrorAction silentlycontinue

$selection = $null
Do
{
cls
write-host Exchange 2010 Transport IP Blocker Manager script be Liran Zamir -ForegroundColor yellow
write-host " "
write-host "Please Select action:"
write-host ""
write-host "1. Add IP to be blocked on the Exchange transport servers"
write-host "2. Remote IP from the Exchange transport servers block list"
write-host "3. Display blocklist from a random transport server"
write-host "X. To quit"
write-host ""
$selection = read-host "Type selection"

if ($selection -eq 1) {
cls
$AddIPblock = Read-Host “Type and IP address to block SMTP connections to Exchange servers”
[ref]$a = $null
if (![system.net.IPAddress]::tryparse($AddIPblock,$a)) { write-host "" ; write-host " !!! The IP address is invalid. !!!" -ForegroundColor white -BackgroundColor red ; read-host " "}
else {

$servers = Get-TransportServer | select name
foreach ($x in $servers) { Add-IPBlockListEntry -IPRange $AddIPblock -server $x.name -ExpirationTime '12/31/9999 11:59:59 PM' }
write-host ""
read-host "IP address was added to the block list"
}
}

if ($selection -eq 2) {
cls
$RemoveIP  = read-host “Type the IP address to remove from the block list”
if (![system.net.IPAddress]::tryparse($RemoveIP,$a)) { write-host "" ; write-host " !!! The IP address is invalid. !!!" -ForegroundColor white -BackgroundColor red ; read-host " "}
else {
$removefromservers = Get-TransportServer | select name,IPIdentity
$r = Get-IPBlockListEntry -server (Get-TransportServer)[0].name | select IPrange
$found = $null
0..($r.count-1) | foreach { $r[$_].iprange ; if ($r[$_].iprange -like $RemoveIP) { $found = "Yes"  } }
if ($found -eq $null) { write-host "" ; write-host " !!! The IP address you typed was not found !!! " -ForegroundColor white -BackgroundColor red ; read-host " " } 
else {
foreach ($s in $removefromservers ) { remove-IPBlockListEntry -identity ((Get-IPBlockListEntry -Server $s.name | where {$_.iprange -eq $RemoveIP  }).identity) -server $s.name -confirm:$false }
write-host ""
read-host "IP address was removed to the block list"
}
}
}

if ($selection -eq 3) {
cls
write-host " "
write-host "List of blocked IP addresses on the transport server "
write-host " "
Get-IPBlockListEntry -server (Get-TransportServer)[0].name | select IPrange
write-host " "
read-host "click Enter to return to menu"
}

} While ( $selection -ne "x")

write-host " "
#####



You will be able to run this script on the Exchange server or on your own workstation as long as you have the Exchange 2010 Powershell management installed.
When you run the script you will be presented with a simple menu

The first option will allow you to specify an IP address (only, no ranges or subnets) to be blocked.
The script then will verify that the IP address type is in a proper IP address format, and then enumerate the hub transport servers and add the IP address to each of those servers with an open-ended expiration date.

The second option will allow you to remove an IP address from the list of blocked addresses.
Here again the IP address you typed will be validated also for correct IP address syntax as well as verify of the first first enumerated Hub Transport server that the typed IP address is indeed set to be blocked.
If all goes well, the IP address will be removed from the blocked IP list on all the HT servers.

The third option allows you to view the list of blocked IP addresses from the first enumerated Hub Transport server.

Please note the script will not work well for removing the last blocked IP address (so you may choose to first add a false IP such as 1.1.1.1 to the list - this will also allow you to verify the Add IP functionality).

The script also does not handle IP subnets or ranges.

Another important note; If you configured a receive connector to specifically allow relay for the IP address or range of IP addresses that includes the IP address you want to block, the block feature will not work until you remove the IP address / subnet / range from the allowed to relay list on the receive connector.

Hope you enjoyed this post... you are welcome to let me know.



Wednesday, February 18, 2015


Auditing mailbox actions for security and accountability

I was facing with a challenge. A company VIP with a few secretaries, and a few mobile devices was facing a serious issue. Calendar items were changing by themselves. Updates were sent to attendees but something changed the meeting date / time on the owner mailbox.
I was asked to find out what is the root cause.

In order to do that, there are two tools:

  1. The Microsoft Exchange Troubleshooting Assistant (Extra.exe) which will allow you to gather the information, but you will have to open a case with MS in order to get the results.
    The process requires to start the tool on the mailbox server of the effected user and target the user mailbox to perform a trace up until the issue occurs
    .
  2. Enable Mailbox Audit on the Exchange Server (2010)

    This will be the path we will investigate


    Enabling mailbox auditing is something that you can do by yourself. The audit can be used for security reasons (see who is abusing his/her assigned permissions to do something that they are not supposed to do), this includes Admins as well as Delegates, but also you can configure to audit the mailbox owner actions which can help with troubleshooting.

    The Audit is enabled per user mailbox and is saved as a part of the mailbox.
    The audit log needs to be enabled, the amount of days to save the audit can be specified (90 days by default), and most importantly, you must configure what to audit.

    In my case, the default owner audit setting did not include all types of operations so it was difficult at first to track the problem. (which was discovered by the trace due to the lack of information). However, after enabling additional audit items on the mailbox owner, it enabled tracking all actions and associating specific calendar actions with a specific ActiveSync mobile device.
    This eventually was found to be the cause of the above problem.

    So... Lets start this thing:

    First, log on with a user with administrative rights to the Exchange server to enable auditing for the user mailbox you would like to investigate.

    Now, Enable auditing on the mailbox with the command:

    Set-Mailbox UserName -AuditEnabled $true

    This command will enable auditing for Admin actions as will as Delegate actions, but not for mailbox owner actions.

    If you run the command Get-Mailbox UserName | select *audit*
    you will see exactly what is audited and what is not:

    AuditEnabled     : True
    AuditLogAgeLimit : 90.00:00:00
    AuditAdmin       : {Update, Move, MoveToDeletedItems, SoftDelete, HardDelete, FolderBind, SendAs, SendOnBehalf, Create}
    AuditDelegate    : {Update, SoftDelete, HardDelete, FolderBind, SendAs, Create}
    AuditOwner       : {}

    You may notice that by default the mailbox owner is not edited.

    If you will run the command: Set-Mailbox Username -auditowner $true
    you will see that the AuditOwner setting changes to:

    AuditOwner       : {Update}

    This is nice, but may not be enough to get all the information you want.

    Lets enable auditing for all options for both Admin, Delegate and owner:

    Set-Mailbox UserName -AuditEnabled $true -AuditAdmin Update,Move,MoveToDeletedItems,SoftDelete,HardDelete,FolderBind,SendAs,SendOnBehalf,Create -AuditDelegate Update,SoftDelete,HardDelete,FolderBind,SendAs,Create
    -AuditOwner Update,Move,MoveToDeletedItems,SoftDelete,HardDelete,Create

    Of course this will consume more space, however you only need to enable this when you need to investigate an issue or on a regular basis for specific users.

    Now, allow some time for the information to be collected.

    When you want to investigate, you will need to view or export the information in order to filter them more easily.

    The command that is used to retrieve the data is:
    Search-MailboxAuditLog UserName -ShowDetails

    This will give you tons of lines if information on every every action performed on every item.
    You can either use powershell to filter the output sent to the screen, or you can more easily send everything (filter or unfiltered) to a CSV file later to be opened in Excel or your favorite spreadsheet.

    Search-MailboxAuditLog UserName -LogonTypes Admin,Delegate,Owner -ShowDetails | export-csv c:\UserName.csv -Encoding utf8

    Please note that you can specify all type of logon types (as shown in the command above) or just specific logon type such as Delegate if you only want to get data about actions performed by the delegates.
    The command -Encoding utf8 will allow exporting of characters that can be identified for non-English (in my case Hebrew) in the item subject.

    You can additionally filter based of available properties, for example, add the following pipe between the Search section and the Export section in order to filter audit items in the calendar folder only | where {$_.FolderPathName -like "\calendar"} | 
    If English is NOT your default folder language you will need to modify the folder name based on your folder language.

    In the CSV file you will get all the detailed information on the actions performed.
    The information also include the client type, such as Outlook and even ActiveSync.
    The ClientInfoString provides the full Device information so you will be able to tell which device performed the action (this is very helpful in case that a few devices are user to sync with the same mailbox).

    Another option to view and filter audit logs for a specific mailbox is using the Exchange Control Panel (ECP) on your exchange server. For example user https://yourserver/ecp



    However, based on available options, it doesn't seem you can view owner actions using this interface.

    I hope this article will provide you with valuable information for troubleshooting.
    If you like this article you are welcome to drop me a line at: liranzamir@gmail.com

     


Monday, September 30, 2013

Testing your Exchange Server ActiveSync



Back in the old days, it was possible to download a kind of virtual Windows Mobile device which you could use to test your Exchange ActiveSync. Today you got more options.

Microsoft Remote Connectivity Analyzer
First, everybody must get to know Microsoft's Remote Connectivity Analyzer found here .















Microsoft did a great job with this tool which continues to evolve over time, providing more and more testing tools, from ActiveSync, to Autodiscover, Web services, Outlook Anywhere, POP/SMTP, Lync and OCS and even the Microsoft  cloud (Office 365).

This online tool often provides detailed information regarding the steps taken and what went wrong.


MobilityDojo.net - EAS - MD Tool
One of my favorite ActiveSync testing tools for some time is MobilityDojo.net 's EAS-MD tool. Click here
The tool, which is also updated by it's creators, supports Exchange 2007/2010/2013.
Unlike Microsoft's Remote Connectivity Analyzer, EAS-MD puts it's focus on ActiveSync and Autodiscover (partially since it still will not analyze Service Connection Point (SCP) data from Active Directory).

However, the thing I like most about this tool, is that it is simple to user, and you can use it anywhere on your network or the Internet.

before we go into a few screenshots, let me give you examples regarding how I put this tool to use:

  • Testing "Before" or "After" your proxy/router  When your infrastructure includes a reverse proxy / TMG server / firewall / router, and you want to troubleshoot ActiveSync connectivity "before" the device or server (on your LAN), or "after" the proxy (in your DMZ or Internet).

    Running synchronization tests with the tool in both locations (something you will usually not be able to do with a real device because of DNS name resolution and networking restrictions) will help you find out if the problem is with the Exchange server, proxy server or even with your ISP.

  • Testing specific CAS servers in a CAS Array 
    Without a direct testing tool, checking each CAS (Client Access Server) in a CAS Array for ActiveSync problems (independent of Exchange's own built in tests and logs), can be very challenging. Using the tool you can simply configure the individual CAS server you want to test.

  • Testing specific user connectivity issues
    If you administer Exchange servers, you probably know the case... A user cannot sync a device, and you have to help him as well as provide proof that your precious Exchange server is not refusing service to the user. All you need to do is have the user enter his credentials into the tool and basic ActiveSync connectivity tests will be performed with his / her mailbox.

  • Creating Fake devices
    Strange... but in an upcoming post I will show you that having too many ActiveSync devices partnered to a specific mailbox can cause you a and your users a lot of headache.
    Before removing real device partnerships (using the upcoming article), you can use the EAS-MD tool to create "Fake" devices with your test mailboxes so you can test the procedures of deleting device partnerships without really using multiple phones or tablets.

  • Checking your SSL Certificates
    The tool can also query and provide information regarding your SSL certificates. The information can also be copied as text for later troubleshooting.

I'm sure that other reasons can be found to use this tool, so lets have a look.

First download the small ZIP file containing the tool from here
The web site states the version as 1.6, but it is actually 1.7. The site also states that Windows 7/2008 are required, but I had no problem running in on Windows XP SP3.

Testing connectivity and Synchronization



The fist screen of the application is usually the one you need for ActiveSync testing.
In the connection parameters enter your (mailbox to be tested) domain credentials, the CAS server name
(This can be from the Internet or from inside your LAN), select to use SSL (who doesn't), and version of Exchange server.

On the upper right, select Trust all certificates. This will have you bypass sync issues that will likely happen when you are testing on your LAN (such as using self signed certificate which you did not bother to install the CA certificate to your test computer, testing a specific CAS server internal FQDN which is not a part of the certificate's Subject Alternate Name, and so on).

Now click Basic Connectivity Test to perform... basic test :-) this test will show you that you are able to talk to the CAS server over ActiveSync and authenticate.

Now you can click Clear Output to clean the screen.

Click Full Sync Test to re-authenticate and actually see a synchronization of the mailbox folders.


Testing AutoDiscover



This test is somewhat disappointing as it still cannot query Active Directory for SCP (Service Connectio Point) which is the source of AutoDiscover information for domain joined workstations.
However, if you rely on DNS records (internal or externally to your network), the tool will query them and show you if it was successful or not and what it found. Use the information for troubleshooting incorrect settings.

Testing the certificate chain


Unless you are using a self signed certificate, the SSL certificate on your Exchange server or proxy server came from a Certificate Authority (CA).
Certificate Authorities are servers which issue digital certificates to other CAs and/or the final SSL certificates (this is a very loose explanation). In order for a certificate to be trusted or "believable" by devices such as ActiveSync devices, web browsers and mail clients, the entire "Certificate chain" must be known and trusted.
Use this tool to query the certificate chain of your Exchange / TMG SSL certificate when the certificate may be the root of the connectivity issues.

Hope this makes sense...

Post your feedback. Please !

Monday, September 23, 2013

Load Powershell Addins in your scripts


It is often that you want to write a script which uses Powershell cmdlets that are not the basic ones found in Powershell v2.0.

For example, you might want to perform actions on Active Directory using Windows 2008 built in AD commands, Exchange 2010 commands or even Quest Active Roles.

Option 1 - Importing the cmdlets from the batch
One option to run a script with Exchange 2010 commands (on a sever running Exchange 2010 or a server with the Exchange management tools installed) is to call the script from from a batch file which loads the Exchange powershell extentions from the batch file. For Example you .cmd or .bat file will look like this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\Scripts\YourScriptName.PS1"


Option 2 - Importing the  cmdlets  from the script
This option - also running on an Exchange server or a server with the Exchange management tools installed, use the batch to load the script using the "Normal" Powershell with this command:

powershell -command "& 'C:/scripts/YourScriptName.ps1'"

and

In the script file, use the following commands to load the needed PSSnapIn:

For Exchange 2010 PSSnapIn
Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.E2010

For Microsoft Active Directory commands (2008)
Import-Module activedirectory

For Microsoft Microsoft Lync 2010
Import-Module Lync

For Quest Active-Roles commands (Free download from Quest software Click Here )
Add-PSSnapin Quest.ActiveRoles.Admanagement


Example:

createmailboxlist.cmd
powershell -command "& 'C:/scripts/Mailboxlistgenerator.ps1'" 


Mailboxlistgenerator.ps1
Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.E2010 
$list = get-mailbox -resultsize unlimited | select name,database,primarysmtpaddress
$list | export-csv c:\scripts\Mailboxlist.csv


Option 3 - Remoting commands to Exchange server
This option allows you to run Exchange Powershell commands from a computer running Powershell with
no Exchange snap-ins by creating a remote session to the Exchange server.
This requires an http connection between the the server or workstation and the Exchange server.
Use the following commands:

$Session = new-pssession -configurationname microsoft.exchange -connectionUri http://ExchangeServerName/powershell
Import-PSSession $Session

From this step you can run Exchange Powershell commands.


Now all you need is to schedule the command by running the batch or run it manually





Thursday, September 19, 2013

Exchange sites you should know



There are TONS of great web site. Information is all over.

I would like you to know some of my favorite Exchange and Powershell sites, which I believe you may find useful.

TechNet Exchange 2010 Virtual Lab
The Virtual Lab provides you a place to learn regarding aspects of Exchange 2010, and even more a small test platform for you to play with if you wish to try something - and you do not have a lab.
Each session will give you 90 minutes of a working Exchange 2010 environment.

Exchange Team Blog
A great site to learn new stuff about Exchange, what's coming up and great drill-downs.

I will add more sites to the list as I go on.


Wednesday, September 18, 2013

The mailbox database size is much larger than the mailboxes.. What's up with that ???


You may notice that the database is much larger than the actual mailbox content.
It is important to know that the database contains additional data.. and that's the Dumpster data.

The database dumpster contains:
- Deleted mailboxes on retention (keep deleted mailboxes for X days in the mailbox database limits tab)
- Deleted items in the mailbox (Keep deleted items for X days in the mailbox database limits tab)
The deleted items in retention include items that were removed then a user empties the "Deleted Items" folder (this is known as "Soft Delete") or when the user Shift+Del an item ("Hard Delete").

All of those items are not counted as a part of the regular mailbox size limit, the dumpster limit is used instead.

Note! Deleted items can be recovered by using Outlook client or using Outlook Web App as long as the number of days that passed since the soft or hard deletion did not exceed the configured retention time that was set on the database Limits properties tab.

Exchange 2010 set a limit to the dumpster by default to the amazing size of 30 GB Per mailbox !
This means that a user with a limited mailbox size of 100 MB can potentially get large Emails, delete them, empty the deleted items folder (or use hard delete: Shift+Del), and than the content will be stored in the dumpster and will not longer be counted for the mailbox size limit.
A user might have a 50 MB mailbox size and up to 30 GB of dumpster items... all of which takes up space in the mailbox database. That is a lot !

important note !
The default dumpster quota size of 30 GB mentioned above is only applied to a mailboxes if a mailboxes are configured to inherit their size limit from the database limit settings.
If you decided NOT to use the size limit settings from the database limits tab, and assign size limits individually, the 30 GB dumpster limit will not take effect at all, in fact user will actually have unlimited dumpster size... This may mean troubles.
The dumpster limits will be ignored when a mailbox is configured on various type of legal hold. If you set one, you probably know about it..

Do large dumpsters effect your Exchange environment ?
Before you decide if and what action to take, wouldn't you like to know what is the actual effect of the dumpster usage in your Exchange databases ? Of course you do.

You can collect this data from the user mailboxes with the following EMS (Exchange Powershell) command:

$MBX = get-mailbox -resultsize unlimited | Get-MailboxStatistics | select displayname,totaldeleteditemsize,database 

The above command will query every mailbox in the Exchange organization and will fetch the name of the owner of the mailbox, the mailbox total dumpster size, and the database containing the mailbox. The results are than stored in an array inside the $MBX variable (Which we can later manipulate). 

Now we would like to view the results easily. We will take the data and sort it by the recoverable items size (dumpster size), largest results first:

$MBX | 
Sort-Object TotalDeletedItemSize -Descending
Now you can take the sorted results, and save them back to the variable:

$MBX = 
$MBX | Sort-Object TotalDeletedItemSize -Descending

Would you like to see only the top five mailboxes ? try this:
(make sure you used the previous command to save the sorted list) :

$mbx | select -first 5

Or get only the list of mailboxes where the dumpster size occupy more 1 GB or more.

$MBX | where {$_.TotalDeletedItemSize -ge 1GB} | Sort-Object TotalDeletedItemSize -Descending

You might also want to export the entire thing to a CSV file to analyze later:

$MBX | export-csv c:\mailboxrecoverables.csv -NoTypeInformation

What about getting the report to your Email ? (Change the second command based on your organization).

$HtmlBody = $mbx | convertto-html | out-string

Send-MailMessage -from Dumpster@yourdomain.com -to YourName@yourdomain.com -Subject "Dumpster Report" -BodyAsHtml $HtmlBody -smtpserver YourExchangeServerName





Not interesting enough ?!?!? Lets put it all into a script which can be scheduled.
The script will fetch the information for all mailboxes as we did before, sort the data based on largest mailbox dumpsters, and Email us only if there are mailboxes with dumpster size over 1GB.


Lets call this script (Click the script name to download) DumpsterReporter.ps1 or DumpsterReporter.zip

#Variables
$filtersize = 300MB
$fromAddress = "DumpsterReport@yourdomain.com"
$ToAddress = "YourEmailAddress@yourdomain.com"
$SMTPServer = "YourExchangeServerFQDN"

# Lets get all the information first
$MBX = get-mailbox -resultsize unlimited | Get-MailboxStatistics | select displayname,totaldeleteditemsize,database

# Find only the mailboxes with dumpster size larger or equal to the limit we chose to look for, save to $results
$results = $mbx | where {$_.totaldeleteditemsize -ge $filtersize} | sort totaldeleteditemsize -descending

# Send the Email only when there are valid results  
If ($results -notlike $null ) 
{
$HtmlBody = $results | convertto-html | out-string
Send-MailMessage -from $fromAddress -to $ToAddress -Subject "Dumpster Report" -BodyAsHtml $HtmlBody -smtpserver $SMTPServer 
}

In order to run the script on schedule on your exchange server, first create a folder for your scripts.
For example: c:\scripts

Save the DumpsterReporter.ps1 script to this folder.
In the folder create a batch / cmd file which will execute the powershell script with the Exchange cmdlets:

for example save the following content in DumpsterReporter.cmd

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\Scripts\DumpsterReporter.PS1"

Now.. all you need to do is to edit the variables in DumpsterReporter.ps1 to march your environment and use the Task Scheduler in control panel to schedule the batch file to run.

To make sure the batch is working fine, first try to run it by double clicking it.

Note that the scheduled task should be set to run with an account which have Exchange permissions, and also select the option "Run whether user is logged on or not"



 Now I know.. what should I do next ?

OK. Now you know if the dumpster size is an issue in your organization or not. It may not be an issue today but it might become one later on so you should consider allocating the dumpster size yourself.

As stated earlier on, setting the Recoverable items Quota can be done on a per Mailbox Database basis, or per Mailbox basis.
The per Database setting will apply to all mailboxes which inherit the mailbox size limit from the database.
The per Mailbox setting is required only when a mailbox is configured with it's own set of limits which are not inherited from the mailbox database.

The behavior of the dumpster quota is FIFO. The oldest item in the dumpster will be removed, even if it did not reach the age to be removed, if a newer item was deleted which caused the quota to exceed the limit.

To set the mailbox database level dumpster warning quota and limit quota use the following command:


Set-MailboxDatabase DatabaseName -RecoverableItemsWarningQuota 3gb -RecoverableItemsQuota 4gb

To set the  dumpster warning quota and limit quota on a mailbox, use the following command:

set-mailbox MailboxName -RecoverableItemsWarningQuota 2GB -RecoverableItemsQuota 3GB

Of course it is up to you to set the appropriate sizes based on your environment. 
What should you consider ?

  • What will be a "Logical" dumpster allocation for a user ?
    This could be impacted by the number of days you set to keep deleted items.
    A user is more likely to have a larger dumpster size for larger number of days.
  • What is the user mailbox size limit ?
    A user with a really limited mailbox size may be forced to repeatedly delete incoming mail.
    This can cause a large dumpster usage, and even more deletion mistakes.
    Consider setting those type of users with at least twice the mailbox size in the dumpster quota.

    For users with large mailboxes, they may not delete items as often, but may accidentally delete an entire folder or folder root with it's sub-folders. Allowing two the mailbox size in dumpster quota may also be useful.
  • What are your storage limits ?
    If storage is tight... get a larger one and enjoy what Exchange 2010 can offer :-).
    But if you cannot do this right now, first consider limiting the number of days that deleted items are retained for the general users. Also use the above script to locate cases of misuse of the dumpster quota either as a result of a regular usage or due to a problem.
  • Which users are more important ?
    Some employee Email are less critical than other. Provide regular mailbox with less days of deleted item retention and smaller dumpster quota, and provide management with more retention days and dumpster quota. This may save you from using tape to restore from backup.
    You could also set a different SLA (Service Level Agreement) for Email recovery for Management and regular users.
How to remedy a full dumpster ?
Well, I did not get to see the FIFO process for myself, yet. However, if your report state that a mailbox contains 20GB of data and it seems highly illogical or unacceptable in the current storage situation, you can ask the user permission to purge part or all of the Dumpster by using Outlook or Outlook Web App.


In Outlook 2010, go to the Folder ribbon, select Recover Deleted Items, and in the list of items, select a large bunch of Emails and permanently delete them with the X icon.

If the dumpster size is really really bug, you might want to look at the items before deleting them in order to find out if a specific Email caused the dumpster to fill, and what was the cause.

There might be other methods of exporting or deleting items in the recoverable items of a mailbox.. I may look into it in a later date.

Cheers
Liran Zamir