Tag: Powershell

How to Purge the Exchange 2010 Dumpster and recover white space instantly

How to Purge the Exchange 2010 Dumpster and recover white space instantly

Summary

If you manage an on-premise Exchange server you’d realise quickly that however huge the disk space was when Exchange server was commissioned that the used space has a funny way of catching up faster than you expected. A key take away with the way Exchange uses its database file is that it never automatically shrinks. So deleting a huge mailbox or asking your users to perform cleanup of their old emails isn’t going to reduce the free space in the partition where your Exchange database resides. What you can do is to monitor the so called white space on a database.

One of the usually forgotten areas to perform a cleanup is on the Deleted  Items folder. It’s surprising how many users want to hold on to all emails – even those deleted months or even years back. The Deleted Items should be cleared as collectively it is a huge wasted space and may affect Exchange and Outlook performance.

Below is the procedure to force the purging of the Recoverable Items\Deletions folder (aka the Dumpster) for a mailbox. The effect is instant and will result to an

  • immediate decrease in the mailbox size
  • immediate increase of the available/white space in the mailbox database of the user.

Background

Exchange 2010 has made significant changes in the way deleted items are handled. Once an email item (message, calendar, contact, etc) is deleted in Outlook it ends up in the Deleted Items folder. The items accumulate here over time, are still part of the mailbox and eat up storage.

If the items are hard-deleted (by pressing Shift – Delete) or if the Deleted Items folder is emptied, the messages end up in the Dumpster. Each mailbox has its own Dumpster. However, it still takes up storage space. It will get automatically purged after 14 days (this is default setting) as part of the regular Exchange maintenance in the background.

In general, the cleanup steps are below:

  • Export a list showing the Deleted Items folder size of each mailbox
  • Empty the Deleted Items folder in Outlook
  • Purge the Dumpster

Note: some steps can be skipped depending on what activity is required.

 

Export a list showing the Deleted Items folder size of each mailbox

  1. Open EMS and run the below cmdlet (this is one long command)
Get-Mailbox -ResultSize Unlimited | Get-MailboxFolderStatistics | where{$_.FolderType -eq "DeletedItems"} | Select-Object Identity, {$_.FolderAndSubFolderSize.ToMb()}, ItemsInFolderAndSubFolders | Export-CSV C:\temp\DeletedItems.csv
  1. Sort according to folder size and identify candidates for cleanup.

 

Empty the Deleted Items folder in Outlook

  1. Discuss with the user the effect of emptying their Deleted Items folder (improved Outlook performance, can’t recover items once emptied, etc)
  2. In Outlook, right click the Deleted Items folder and select Properties.
  3. Click Folder Size button and take note of the Total size of the folder. This is an indication of how much white space that can be recovered. Click Close.
  4. In Outlook, right click the Deleted Items folder and select Empty Folder. Click Yes. This may take a few minutes depending on the size of the folder.

Purge the Dumpster

  1. View the size of the mailbox and how much space is consumed by the mailbox’s Dumpster. Go to EMS and run the below three cmdlets.
Get-MailboxStatistics -Identity <mailbox alias> | Select DisplayName,ItemCount,TotalItemSize
Get-MailboxStatistics -Identity <mailbox alias>| select DisplayName,TotalDeletedItemSize
Get-MailboxFolderStatistics -Identity <mailbox alias> -FolderScope RecoverableItems | Select Identity,ItemsInFolder,FolderAndSubfolderSize

Purge-Dumpster1

2.View how much white space is available in the mailbox database using the below cmdlet.

Get-MailboxDatabase -Status | ft Name,DatabaseSize,AvailableNewMailboxSpace –auto

Purge-Dumpster2

3. Purge the Dumpster using the below cmdlet. This may take a few minutes but the effect is immediate (ie mailbox size should decrease and database white space should increase instantly).

Search-Mailbox -Identity <mailbox alias> -SearchDumpsterOnly –DeleteContent

Purge-Dumpster3

4. Run the commands in #1 and #2 above to confirm the changes took effect

        Purge-Dumpster4

Strange Outlook issue (Inbox of secondary mailbox doesn’t update)

Strange Outlook issue (Inbox of secondary mailbox doesn’t update)

This issue was escalated to me as it has bugged tech support and the affected users for a while.

Setup:

  • Email System: Office 365/Exchange Online
  • Outlook version: Office 2016  (via O365 subscription)

Observations:

UserA has been given full access to UserB’s mailbox (via Exchange Admin Centre – Recipients – User Properties – Mailbox Delegation – Full Access).

UserA can see UserB’s emails (Inbox and subfolders) in Outlook. However, UserB’s Inbox doesn’t automatically update. The workaround is for UserA to keep going to Send/Receive tab and click Update Folder which triggers a refresh and arrival of new emails in UserB’s Inbox.

The reverse doesn’t seem to happen. All settings being similar, UserB can see UserA’s emails in Outlook and it automatically updates with UserA’s new emails.

What has been done:

  • Permissions checked. Full permission to access each other.
  • Windows and Office patches all up to date.
  • Behavior when using OWA is ok. Which made us think it is an Outlook issue.
  • Outlook profile of UserA has been re-created.
  • Office/Outlook in UserA has been uninstalled then reinstalled.
  • Both users have deleted a lot of emails and shrunk their mailbox sizes.

Cause:

This is a documented issue when the secondary mailbox contains a LOT of email folders (Note: folders and NOT messages). In the case of UserB, she had 986. The command to find this via Powershell is below.

(Get-MailboxFolderStatistics UserB).count

Solution:

Reduce the number of mail folders (preferably to less than 500).

Active Directory Account and Exchange Mailbox Cleanup Procedures

Active Directory Account and Exchange Mailbox Cleanup Procedures

As part of regular account maintenance, Active Directory user accounts and Exchange 2010 mailboxes of previous staff should be deleted from the system after a period of time. Below are the steps required to perform this clean up.

Note: some steps can be skipped depending on what activity is required.

In general, the cleanup steps are below:

  • Perform AD Account/Mailbox Inventory
  • Export Mailboxes to PST
  • Remove ex-staff’s AD Account and Mailbox

*************************************************************************

 Perform AD Account/Mailbox Inventory

  1. Go to Active Directory Users and Computers (ADUC) – ExStaff OU and review the accounts.
  2. Open Exchange Management Shell (EMS) and determine the mailbox sizes using the below cmdlet (Note: this is one long command)
Get-Mailbox -OrganizationalUnit "ou=ExStaff,dc=XXXXX,dc=com" | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize,Database
  1. Check with the ex-staff’s manager what to do with the mailbox
  • Review email addresses assigned to ex-staff and any email forwarding that is set
  • Decide on what to do: Just delete? Assign alias to manager/other staff before delete?

 

Export mailboxes to PST

  1. Ensure there’s enough free space in the disk partition of the server that will store the PSTs (eg shared as \\server1\psts$)
  1. Open EMS and run the mailbox export request cmdlet below to export the mailbox.
New-MailboxExportRequest –Mailbox joe.bloggs –FilePath \\server1\pst$\Joe.Blogss.pst
  1. Get mailbox export request status using the below cmdlet.
Get-MailboxExportRequest

Or, to get the % completion use the below cmdlet.

Get-MailboxExportRequest | Get-MailboxExportRequestStatistics

AD-Cleanup-00

  1. When the mailbox export request is completed the request remains on the server until it is removed. Complete the mailbox export request using the cmdlet below.
Get-MailboxExportRequest | where {$_.status -eq "Completed"} | Remove-MailboxExportRequest

 

Remove ex-staff’s AD Account and Mailbox

  1. Get a screenshot of the current Database Size and White Space Size of all databases using the cmdlet below.
Get-MailboxDatabase -Status | ft Name,DatabaseSize,AvailableNewMailboxSpace -auto
  1. Use the below cmdlet to remove BOTH the Exchange mailbox and the user account from Active Directory. Note this step is irreversible.

Remove-Mailbox –identity joe.bloggs –permanent $true

AD-Cleanup-01

  1. After a minute, run the cmdlet in Step 1 again to see if the white space space has increased.

AD-Cleanup-1

4. Backup (or Delete) the user’s Home Directory

 

Connect to Office 365 via Powershell

Background

Most administration of Office 365 is done using the Office 365 Admin Center (https://portal.office.com/admin) eg license assignment, domain management, email maintenance (via Exchange Admin Center link) etc.

Administering Exchange via Powershell is still possible however there are extra steps involved due to increased security required in accessing cloud resources.

Below are the prerequisites and steps to connect to Office 365 via Powershell

Prerequisites

  • Windows 8, 10 or 2012/R2
  • Microsoft.NET Framework 4.5 or later

Steps

1. On your local computer, open Windows Powershell (as local administrator) and run the following command.

$UserCredential = Get-Credential

In the Windows PowerShell Credential Request dialog box, type your Office 365 user name (eg admin@<tenant name>.onmicrosoft.com) and password and then click OK.

2. Run the following command.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

3. Run the following command.

Import-PSSession $Session

4. You are now ready to enter your Powershell cmdlets,

eg:
Get-MailboxStatistics joe.bloggs | ft DisplayName, TotalItemSize, ItemCount

5. (Important) When finished do not just click the top right X. Instead disconnect the remote Powershell session properly by running the command below.

Remove-PSSession $Session