Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save constructor-igor/e80e24c5501c3a222283 to your computer and use it in GitHub Desktop.
Save constructor-igor/e80e24c5501c3a222283 to your computer and use it in GitHub Desktop.
Powershell: list of all entries from Outlook Global Address List (GAL)
[Microsoft.Office.Interop.Outlook.Application] $outlook = New-Object -ComObject Outlook.Application
$entries = $outlook.Session.GetGlobalAddressList().AddressEntries
$count = $entries.Count
$count
foreach($entry in $entries)
{
[console]::WriteLine("{0}: {1}", $entry.Name, $entry.GetExchangeUser().MobileTelephoneNumber)
}
@ZaxLofful
Copy link

how do we get custom attribute 1 from GetExchangeUser() ??

If you want to access the attributes of the user, use the (.) notation, to access more properties.

The function GetExchagneUser() will try to go online and find a user with that name instead of just using the data you already have in the variable.

Example:

$entry.Manager.Name

@ppagal
Copy link

ppagal commented Mar 27, 2019

Can someone help me expand on this code? What I would like to do is only hit the exchange server 1 time and also look for a specific filter like "title" and "location" I've modified this code slightly to create an object but there is 62,000 + contacts on my GAL. I'd like to only search for contacts with a specific title and then also a specific location / city. Below is my updated code, but when I run it, it still continues to try to pull all 62,000+ contacts. Is there a way to insert filters on what I'm looking for without pulling all the contacts?

`[Microsoft.Office.Interop.Outlook.Application] $outlook = New-Object -ComObject Outlook.Application
$entries = $outlook.Session.GetGlobalAddressList().AddressEntries
$count = $entries.Count
$count
$objs = @()
foreach($entry in $entries)
{
$attributes = $entry.GetExchangeUser()
$city = $attributes.city
$title = $attributes.jobtitle
$email = $attributes.primarySMTpaddress
$name = $attributes.name

$obj = [pscustomobject]@{
        Name = $name
        City = $city
        Title = $title
        Email = $email
        }
$objs += $obj
#[console]::WriteLine("{0}: {1}", $entry.Name, $entry.GetExchangeUser().primarySMTPaddress)

}`

@dhivyamaig
Copy link

Is this problem solved?

@robertcatgithub
Copy link

Thanks for the code , I can use it.
My GAL is under 20K so I just iterate thru $entries multiple times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment