Category Archives: Powershell

Find email address in Public Folders

Looking after several thousand mailboxes, public folders and distribution groups can sometimes make it difficult for you to keep track on where certain email aliases are assigned.

Now mailboxes, distribution groups and mail contacts are easy as you can add a filter in the Exchange Management Console to find these, however the same cannot be applied for Public folders.

Once again PowerShell comes to the rescue in the form of the Exchange Management Shell. Running the following command will bring up all the details you need:

Get-MailPublicFolder | Get-PublicFolder

This command will bring up the name of the public folder along with the parent path so you know exactly where the public folder lives by showing the folder name and the parent path so you can navigate to the folder in question.

output from Get-MailPublicFolder

Not only do you get to find the public folder you get to learn a little more about Power Shell with the nice “Tip of the day” that appear in the Exchange Management Shell

Now that deserves a beer!

Create new mail contacts from a CSV file for Exchange 2007/2010

Today I had a colleague come to me, asking for help as she had a user asking to have 649 mail contacts created and added to a distribution group by the end of the day.

Now instead of sitting there and slowly adding in each and every single contact individually (which if you’ve had to do this before in Exchange you’ll know it’s an absolute nightmare!!) I decided to modify a script I wrote a while back for importing mailboxes from a CSV file.

So the format of the CSV file should be:

Name Email OUPAth
Test User domain.local/Mail Contacts/Test

For the OUPath you can easily find this out by going into your Active Directory and right clicking on the folder you wish the mail contacts to be imported into, and going to Properties
OU Properties

As you can see in the Object section you can find out the OU Path, by looking at the Canonical name of object:

Once the .CSV file is created and formatted correctly you can use this wonderful little powershell script I wrote:

Import-CSV C:\createnewcontact.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.Email -Name $_.Name -OrganizationalUnit $_.OUpath

Now I’ll talk you through section by section on what this script does so you’re a little more aware (and i can prove I didn’t just copy and paste from a website :p)

Now “Import-CSV C:\createnewcontact.csv” basically tells Powershell to import data from the CSV file which lives directly on the C:\ and is called createnewcontact.csv (bare in mind if you call your CSV differently you will need to change this section)

“ForEach-Object”{ allows you to perform an action on each item in the collection (in this case everything between the { }

“New-MailContact” This is kind of self-explainatory to be honest. If you want a new mailbox you put in New-Mailbox and for a new mail contact you use New-MailContact

Now when you run New-MailContact manually into PowerShell it asks you for 2 pieces of information:

  • ExternalEmailAddress
  • Name

So when your PowerShell script runs New-MailContact it still needs this information. So by using “-ExternalEmailAddress$_.Email” you are telling the script that when it gets asks what the -ExternalEmailAddress is the PowerShell sees $_.Email which signifies to it that it should get this information from the Email column ($_. tells it to use the column and the name after it is the column name)

This is the same for -Name $_.Name -OrganizationalUnit $_.OUpath

I’m not the greatest at explaining things so I do apologise. If in doubt just copy exactly what I’ve done and you’ll be fine 🙂

Mailcontact Powershell

Pop in the location of the script into Power Shell (or if you’re really lazy just drag and drop the script from Explorer into the Power Shell window) and hit enter and watch it run away and create hundreds of mail contacts from your .CSV file in seconds…and then have a beer