Posted by: Andy Grogan | May 19, 2008

Exchange 2007 Mailbox Data Orientation…

This post I guess loosely follows on from my previous article about Orientation for Exchange admins whom are most used to 2003 administration.

My migration to Exchange 2007 has indeed come on leaps and bounds in the last couple of weeks where I am now at the point where I have a number of people within my team fully migrated to Exchange 2007 which is part of my UAT phase (User Acceptance Testing).

Now that we have live users running on one of the new clusters today I set about working on some familiarisation training with my team (whom will be running the whole shebang when I am gone) where the focus of the afternoon was differences between the Exchange 2003 System Manager and the Exchange 2007 Management Console (I had hoped to run through the management shell at a later point).

Essentially as this was an open session of familiarisation for the team I asked them to look at the Management Console and raise questions about features which appeared to be missing – it was at this stage I was hit with the following questions;

  • How can I get a list of mailboxes within a store?
  • How can I tell when the users last logged on or off?
  • How do I know the size of their mailbox and items contained?
  • What about disconnected mailboxes – how do we find them?
  • How to we remove disconnected mailboxes?
  • How do we reconnect them?
  • How do we purge mailboxes?

 

Wow I thought, I have opened myself up here!

The first three questions have a very neat a simple solution – although it is true the functionality to view such data is gone from the GUI – it have by no means been removed from the Exchange 2007 Management Shell. Although I had not intended to scare them with the EMS just yet – I though that this was a great subject to how show them how powerful it can be.

So I opened up the Exchange 2007 Management Shell and typed in the following cmdlet:

Get-MailboxStatistics -Database <your database> | export-csv -path c:\MB.csv

For example;

PSTip3

The above command will create a CSV file in the root of the server’s C:\ drive named MB.csv which when open looks like the following:

PSTip4

Already beginning to see the power here over the original Exchange System Manager they asked how would the syntax change if they were looking for data on a specific specific mailbox.

It was here that I explained that you can retrieve an number of items of information about a specific mailbox if you know the attributes to query – for example – using Get-MailboxStatistics you can query the following attributes of a given mailbox: 

AssociatedItemCount
DeletedItemCount
DisconnectDate
DisplayName
ItemCount
LastLoggedOnUserAccount
LastLogoffTime
LastLogonTime
LegacyDN
MailboxGuid
ObjectClass
StorageLimitStatus
TotalDeletedItemSize
TotalItemSize
Database
ServerName
StorageGroupName
DatabaseName
Identity
IsValid
OriginatingServer

Therefore if I wished to know the  LastLogoffTime, MailboxGuid and ItemCount of a specific mailbox called “Andy” I would use the following command;

Get-MailboxStatistics -Identity andy | select LastLogoffTime,MailboxGUID,ItemCount

Which would give me the following output:

PSTip5

You can also combine the above with the “Export-CSV” cmdlet to get that data to a CSV file – or indeed if you are more of a purest you can modify the command to straight port to a text file by changing it to look like:

Get-MailboxStatistics -Identity andy | select LastLogoffTime,MailboxGUID,ItemCount >c:\andy.txt

Gathering speed another question that was asked was “If I don’t know the name of the store that a user is in – can I still gain access to the mailbox properties”.

Now although still a very easy task to accomplish it would require three separate lines of script to be typed into the Exchange Management Console – therefore this is where I decided to introduce the team to POWERGUI.

I suspect that most of you will be familiar with PowerGUI, but for those of you whom are not  – essentially it is an interface which provides a GUI Front end to a number of Powershell based commands – however one of the best parts of it is that it includes a dedicated Powershell syntax Editor where you can construct scripts and execute them directly.

If you choose to download and use the PowerGUI syntax editor on your Exchange server before you begin open a Exchange Management Shell command line and type in the follow:

Set-ExecutionPolicy RemoteSigned – this will allow for you to run scripts from the the PowerGUI Syntax Editor.

In order to get data on a specific mailbox without knowing the store in which is resides you can use the following script;

$MBS = Get-MailboxDatabase

$Mailbox = Read-Host “Please Provide the Display Name of a mailbox to Query.”

ForEach($Number in $MBS){
Get-MailboxStatistics -Database $Number | where {$_.DisplayName -eq $Mailbox } | fl
}

One of the exciting things that my team began to see was that although the command line is typically a scary place to be if you are not used to it – it can save you a tremendous amount time – essentially as the diagram below depicts that a simple set of commands can be quicker than having to locate the exact node within a GUI.

PSTip5

Another question that was asked was how you can locate disconnected mailboxes within Exchange 2007. Now, you can use the Exchange Management Console via [ Recipient Configuration - > Disconnected Mailbox ] - see below;

 EMC-Dis

However it is almost as quick to have the following script saved in Powershell and Execute is via the Powershell Syntax editor;

$MBS = Get-MailboxDatabase

ForEach($Number in $MBS){
Get-MailboxStatistics -Database $Number | where {$_.DisconnectDate -ne $null} | fl
}

The above script will retrieve a list of all the mailboxes that have been found within all storage groups within your Mailbox Servers – however with a few minor changes you can turn this script into another powerful admin tool – essentially a script that will find all disconnected mailboxes and ask if you would like to reconnect them;

$MBS = Get-MailboxDatabase

ForEach($Number in $MBS){
    $box = Get-MailboxStatistics -Database $Number | where {$_.DisconnectDate -ne $null} | select MailboxGUID,DisplayName
    Write-Host $box
    $Choice = Read-Host “Do you wish to reconnect this mailbox?”
    If ($Choice.ToLower() -eq “y”){
        $User = Read-Host “Please enter in an AD User Account”
     &nbsp
;  Connect-Mailbox -Database $Number -Identity $box.MailboxGUID -user $User -Alias $user
    }else{
        Write-Host “Current Mailbox Skipped”
    }
}

If successful the above script will produce the following output;

PSTip7

The final question that I was asked was how to you purge mailboxes from the store as there does not appear to be a way to do it via the GUI.

Essentially the principle of “Purge” has been removed from Exchange 2007 – and replaced with the concept of “Remove” – the following script which will Remove disconnected mailboxes from all your stores is a variation on the above reconnection script;

$MBS = Get-MailboxDatabase

ForEach($Number in $MBS){
    $box = Get-MailboxStatistics -Database $Number | where {$_.DisconnectDate -ne $null} | select MailboxGUID,DisplayName
    Write-Host $box
    $Choice = Read-Host “Do you wish to PURGE this mailbox?”
    If ($Choice.ToLower() -eq “y”){
        Remove-Mailbox -Database $Number -StoreMailboxIdentity $box.MailboxGUID -Confirm:$False
    }else{
        Write-Host “Current Mailbox Skipped”
    }
}

I hope that you find some of the above useful – and I do recommend downloading and installing POWERGUI as it can allow you to create a number of general purpose scripts for managing your Exchange environment which can be used over and over again.


Responses

  1. [...] Exchange 2007 Mailbox Data Orientation… [...]


Leave a response

Your response:

Categories