MSExchangeGuru.com

Learn Exchange the Guru way !!!

 

Automating mailbox location tracing for Microsoft Exchange mixed mode

“Someone” deleted a user account from your AD environment and now you’ve been asked to restore it. You will have no idea where it was residing and even if you found that out, where the heck was the mailbox? Now imagine if that account belonged to the VP of the company… Oh boy!!!

So, this came to me as a requirement and I looked up over internet and couldn’t find any. So decided to write one on my own. I will try to put this in layman terms to ensure both Mr.Perfect and Mr.JustOk can follow it.

Scenario:

If an exchange mailbox for an account is deleted, exchange will mark it as disconnected mailbox and it will be deleted post the retention period set in your organization. To reconnect that mailbox, it is mandatory to know where it was residing so that you could navigate to that database and reconnect it to an AD account. Exchange does not possess the functionality to remember or audit the mailbox location of a user by default.

Solution:

This is a script which will collect details of all user accounts in the following order:

Name Alias PrimarySmtpAddress Database Identity

So here we go:

  1. Have a machine dedicated for this purpose. I will call it ExchSrvr.MSExchangeGuru.com. It can be a mailbox server, but remember the output of this script will depend upon how big your organization is and this will create an output every week/how frequent you want to schedule it.

    To give you a rough idea: The output for an organization with about 30000 users was 4.5MB when I ran it. So, do you math’s and find out the output file size.

  2. Create a folder à C:\Scripts\MailboxReport
  3. Run “Set-ExecutionPolicy RemoteSigned” cmdlet in shell since this is a custom script and it won’t run if it’s not signed.
  4. Copy this script and paste it to “C:\Scripts\MailboxReport\” with name “_MailboxReport_Script.ps1”
# _MailboxReport_Script.ps1 – Get the report of all user mailboxes and their server location and database.
# Created by – www.MSExchangeGuru.com$AdminSessionADSettings.ViewEntireForest =$True
#Adding Exchange Snap In to execute Exchange CmdLets in this script

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

#Get UserBase report to CSV file

$strB = Get-Date

$strDt = “C:\Scripts\MailboxReport\MailboxReport_” + $strB.Year + $strB.Month + $strB.Day + “_” +$strB.Hour + $strB.Minute + “.CSV”

Get-Mailbox -ResultSize Unlimited | Select Name, Alias, PrimarySmtpAddress, Database, Identity| Export-CSV $strDt

#Send an email

$FromAddress = “MailboxReport@MSExchangeGuru.com”

$ToAddress = “Meera@MSExchangeGuru.com, Sai@MSExchangeGuru.com, Sunder@MSExchangeGuru.com,
Ratish@MSExchangeGuru.com”

$MessageSubject = “Mailbox Report”

$MessageBody = “Hi Team,

Attached is the MSExchangeGuru Mailbox Report for this week.


Ratish Nair

$SendingServer = “Type the FQDN of your HubTransport server or your Gateway server which can send emails

$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody

$Attachment = New-Object Net.Mail.Attachment($strDt)

$SMTPMessage.Attachments.Add($Attachment)

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer

$SMTPClient.Send($SMTPMessage)

Let me tell you what this script means:

$AdminSessionADSettings.ViewEntireForest =$True – allows you to open a session for the entire forest, so if you have multiple domains, you don’t have to run this script for each domain.

$strDt = “C:\Scripts\MailboxReport\MailboxReport_” + $strB.Year + $strB.Month + $strB.Day + “_” +$strB.Hour + $strB.Minute + “.CSV” – This is where we specify the output file name. So if I run the script at 10.15am on 5/20/11 the output will be named as MailboxReport_2011520_1015.csv

Now we run the cmdlet specified in the script to get the output.

Once the output is created, we send an email from “any” email address to a set of recipients.

I have marked some fields like this. You need to edit these areas to suit your organization requirements.

  1. Once the _MailboxReport_Script.ps1 is created, try running it once to ensure you are getting the required output along with the automated email.
  2. If you don’t want the script to parse the entire directory while testing, just remove “ResultSize Unlimited” from the line “Get-Mailbox -ResultSize Unlimited | Select Name, Alias, PrimarySmtpAddress, Database, Identity| Export-CSV $strDt” and replace it with the alias of a user.
  3. Once the script is doing “what it is supposed to be doing”, just schedule it using Windows scheduler to run every week.

NOTE– The output of this script is vital for any/every organization. It is important to have a backup of its output every week. This can be used for Auditing, DR and administrative purposes. If you don’t have a similar thing running, go ahead and set it up right away.

Thanks,

Ratish Nair
MVP Exchange
Team@ MSExchangeGuru

Keywords: find list of all users in exchange, find list of all mailboxes in exchange, tracing mailbox location, script to find mailbox location in exchange 2007, script to send emails weekly, script to find all users, find all users mailbox database location, script to find all users in exchange 2007, automating scripts, automating a command

6 Responses to “Automating mailbox location tracing for Microsoft Exchange mixed mode”

  1. Charles Derber Says:

    Thanks…It was informative to me…!

  2. nonita Says:

    Awesome work!! U simply made this so dam easy… it was indeed informative.. 🙂

  3. Vishwanath Says:

    Hi Ratish,

    I would like to know if there is any script where I can find all mailbox users who are not having legacy exchange dn attributes
    set for the entire mailboxes. Not individually database by the whole forest.

    We faced a situation where some migrated users did not had legacyexchanedn value set which resulted in not processing mail submission service ending in no OOF reply for users in the same database.

  4. Ratish Sekhar Says:

    @Vishwanath – Try something like this:

    Get-Mailbox -ResultSize Unlimited | Select Name, Alias, LegacyExchangeDN >>C:\Output.txt

    The output will give you all users with LegacyExchangeDN, then play with excel. Im sure there is a better way to do this though…

  5. Avinash Says:

    Hi,

    Great Script and write up.

    Please help me in adding Mailbox Size in this CSV.

  6. Manoj Vijaykumar Says:

    Great script bro. Good job and congrats once again on being MVP.

Leave a Reply

ad

Categories

Archives