Recently we’ve had a couple of clients want to migrate from other hosted Exchange offerings to Microsoft Exchange Online. The problem we were running into was their hosters didn’t want to give us an export of their existing directory information (Names, Phone numbers, SMTP Addresses, etc), so we could import it into the client’s local AD or directly into Microsoft Online. After going through the pain of manaully typing in the information once, populating Group membership, etc, we thought there has to be a better way. Sure enough it didn’t take long to find one. It turns out that Outlook 2007 allows you to access some the attributes that are displayed in the GAL.

Using this access we created a PowerShell script you can use to export user information such as name, Primary SMTP address, phone numbers, etc, as well as group and contact information from any Exchange environment to CSV files. Once you have the information in CSV files it’s easy to import into Active Directory or directly into Microsoft Online (user objects only). The script creates 4 csv files:

  • User Objects.csv – Contains directory information for user objects
  • Group Objects.csv – Contains directory information for group objects
  • Contact Objects.csv – Contains directory information for contact objects
  • Group Membership.csv – Contains information about group membership. The format of the file is the SMTP address of the group followed by the SMTP addresses of the group members. If importing information into your local AD you’ll need another script to actually use this file. Contact us at [email protected] if you need a script to do this.

You can download a properly formatted version of the script here.


#Outlook Directory Export
#Written By Chad Mosman, MessageOps, www.MessageOps.com
#
#This script uses Outlook 2007 to export Directory Information from Exchange
#
#To run the script just log into your mailbox using Outlook 2007 and run the script
#
#If there are a large number of itmes in your Global Address List it is recommended
#that you temporarily disable the Programmatic Access security in Outlook. To do this:
#
# 1. From the Toos Menu select Trust Center
# 2. Click Programmatic Access
# 3. Choose Never Warn me about suspicious activity
#
#

$Outlook = New-Object -Comobject Outlook.Application
$Mapi = $Outlook.GetNamespace(“MAPI”)
$Gal = $Mapi.GetGlobalAddressList()

[email protected]()
[email protected]()
[email protected]()
[email protected]()

ForEach ($Entry In $Gal.AddressEntries)
{
“Gathering Information on object ” + $entry.name
#UserObjects
If ($entry.AddressEntryUserType -eq 0) {
$userobject = $entry.getExchangeUser() | select Name,Alias,FirstName,LastName,`
PrimarySMTPAddress, Address,Manager,AssistantName, BusinessTelephoneNumber, City, `
Comments,CompanyName,Department,Jobtitle, MobileTelephoneNumber,OfficeLocation, `
Postalcode, StateorProvince, StreetAddress
$usercollection += $userobject
}

#GroupObjects
ElseIf($entry.AddressEntryUserType -eq 1){
$groupobject = $entry.GetExchangeDistributionList() | select Name,Alias,PrimarySmtpAddress,Comments
$groupcollection += $groupobject

$groupobject = $entry.GetExchangeDistributionList()
$members = $groupobject.GetExchangeDistributionListMembers()

$membersobj= “” | select GroupSMTP,MembersSMTP
$smtpmembers =””
ForEach ($member in $members){

If ($member.AddressEntryUserType -eq 0) {
$membersmtp = $member.getExchangeUser() |select PrimarySmtpAddress
$smtpmembers += $membersmtp.PrimarySMTPAddress + “,”
}
ElseIf($member.AddressEntryUserType -eq 1){
$membersmtp = $member.GetExchangeDistributionList() | select PrimarySmtpAddress
$smtpmembers += $membersmtp.PrimarySMTPAddress + “,”
}
ElseIf($member.AddressEntryUserType -eq 5){
$membersmtp = $member.GetExchangeUser() | select PrimarySmtpAddress
$smtpmembers += $membersmtp.PrimarySMTPAddress + “,”
}
}

If ($smtpmembers.length -gt 0){
$smtpmembers= $smtpmembers.substring(0,$smtpmembers.length-1)
$membersobj.GroupSMTP=$groupobject.PrimarySMTPAddress
$membersobj.MembersSMTP=$smtpmembers
$groupmembercollection += $membersobj
}

}

#ContactObjects
ElseIf($entry.AddressEntryUserType -eq 5){
$Contactobject = $entry.getExchangeUser() | select Name,Alias,FirstName,LastName,`
PrimarySMTPAddress, Address,Manager,AssistantName, BusinessTelephoneNumber, City, `
Comments,CompanyName,Department,Jobtitle, MobileTelephoneNumber,OfficeLocation, `
Postalcode, StateorProvince, StreetAddress
$contactcollection += $contactobject
}

}

 

$Usercollection | Export-Csv "User Objects.csv" -NoTypeInformation
$GroupCollection | Export-CSV "Group Objects.csv" -NoTypeInformation
$groupmembercollection | Export-CSV "Group Membership.csv" -NoTypeInformation
$ContactCollection | Export-CSV "Contact Objects.csv" -NoTypeInformation

As always, if you have any questions, run into problems, or need a customized version, please let us know and we’ll be happy to help. Just email us at [email protected]

Was this article helpful?
YesNo