Freigeben über


Export User GAL Entries from Outlook

This morning, looking for an answer to something, I stumbled across a question that seemed easy enough to fix: Is it possible to export the GAL from Outlook if I don't have access to a server?

Yes, yes it is.  Since we have the Power of Grayskul--err, PowerShell, at our disposal, we can manipulate Outlook to return this data to us.  All it takes is a little code.

 param (
     $OutFile = (Get-Date -Format yyyy-MM-dd) + "_GALEntries.csv"
)
$Outlook = New-Object -ComObject Outlook.Application
$GlobalAddressList = $Outlook.Session.GetGlobalAddressList().AddressEntries
$TotalObjects = $GlobalAddressList.Count
$i = 1
foreach ($entry in $GlobalAddressList)
{
 Write-Progress -Activity "Exporting Global Address List Entries" -PercentComplete (($i / $TotalObjects) * 100) -Status "$($TotalObjects - $i) entries remaining"
    If ($entry.Address -match "\/o\=")
  {
       $RecordData = [ordered]@{
           Name   = $entry.Name
            PrimarySmtpAddress = $entry.GetExchangeUser().PrimarySmtpAddress
            x500   = $entry.Address
     }
       $Record = New-Object PSobject -Property $RecordData
     $Record | Export-csv $OutFile -NoTypeInformation -Append
    }
   $i++
}

You'll notice that I called the GetExchangeUser() method for the $entry object.  There are a number of methods that we can return for the $entry object:

 PS C:\temp> ($entry | gm -MemberType Method).Name
Delete
Details
GetContact
GetExchangeDistributionList
GetExchangeUser
GetFreeBusy
Update
UpdateFreeBusy

Calling GetExchangeUser() on the $entry object reveals ooh-gobs of properties that we can use:

 PS C:\temp> ($entry.GetExchangeUser() | gm -Type Property).Name
Address
AddressEntryUserType
Alias
Application
AssistantName
BusinessTelephoneNumber
City
Class
Comments
CompanyName
Department
DisplayType
FirstName
ID
JobTitle
LastName
Manager
MAPIOBJECT
Members
MobileTelephoneNumber
Name
OfficeLocation
Parent
PostalCode
PrimarySmtpAddress
PropertyAccessor
Session
StateOrProvince
StreetAddress
Type
YomiCompanyName
YomiDepartment
YomiDisplayName
YomiFirstName
YomiLastName

Go, make a list or something.  You can grab the completed script at https://gallery.technet.microsoft.com/Export-GAL-from-Outlook-GAL-49cee015.