VinsWorldcom has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get information from the Outlook Global Address List (GAL). I've used OLE and Outlook pretty successfully before and I'm connecting and getting some information now, but can't seem to expand the output.

#!perl use strict; use warnings; use Win32::OLE; my $outlook = Win32::OLE->new('Outlook.Application'); die unless $outlook; my $namespace = $outlook->GetNamespace("MAPI"); for my $k (sort(keys(%{$namespace->AddressLists->Item("Global Address +List")->AddressEntries("Lastname,Firstname")}))) { printf "$k = %s\n", $namespace->AddressLists->Item("Global Address + List")->AddressEntries("Lastname,Firstname")->$k; }

The above produces the following output (admittedly the Lastname,Firstname has been changed as well as the data retuned in 'ID' to obfuscate any sensitive data):

VinsWorldcom@C:\Users\VinsWorldcom\tmp> test.pl Address = /O=EXCHANGE/OU=ORG/CN=RECIPIENTS/CN=LASTNAFI1 AddressEntryUserType = 0 Application = Win32::OLE=HASH(0x2821978) Class = 8 DisplayType = 0 ID = 00000000AABBCCDDEEFFAABBCCDDEEFFAABBCCDDEE00000000000000AABBCCDDE +EFFAABBCCDDEEFFAABBCCDDEEFFAABBCCDDEEFFAABBCCDDEEFFAABBCCDDEEFFAABBCC +DDEEFFAABBCCDDEE00 Name = Lastname,Firstname Parent = Win32::OLE=HASH(0x28219f0) PropertyAccessor = Win32::OLE=HASH(0x2821990) Session = Win32::OLE=HASH(0x2821a08) Type = EX

The issue is the only relevant information from the output above is "Name". Looking at the GAL in Outlook, there are a ton of other fields (e.g., Address, phone number, email address, manager, etc.). I did a "print pack 'H*', $<ID>" and a bunch of hex is the first part followed by the content in the "Address" output. Certainly not enough encoded data to produce all the missing fields.

I've done some expansion of the "Win32::OLE=HASH(...)" values and they don't return anything useful either - just values for:

Application = Win32::OLE=HASH(0x26c16c0) Class = 112 Parent = Win32::OLE=HASH(0x26c1720) Session = Win32::OLE=HASH(0x26c16d8)

Some Google-ing has produced (among others):

UPDATE: Reference here: https://msdn.microsoft.com/en-us/library/office/ff869721.aspx and solved it.

for my $k (sort(keys(%{$namespace->AddressLists->Item("Global Address +List")->AddressEntries("Lastname,Firstname")->GetExchangeUser}))) { printf "$k = %s\n", $namespace->AddressLists->Item("Global Address + List")->AddressEntries("Lastname,Firstname")->GetExchangeUser->$k; }

Replies are listed 'Best First'.
Re: Info from Outlook Global Address List
by Anonymous Monk on May 19, 2015 at 12:39 UTC
    The api that isnt working, what err msg does it give?

      It varies probably since I'm not using the API correctly. Reference https://msdn.microsoft.com/en-us/library/office/ff868350.aspx for example:

      $namespace->AddressLists->Item("Global Address List")->AddressEntries( +"Lastname,Firstname")->PropertyAccessor->GetProperty("0x007D001E");

      will give me a "Use of uninitialized value in printf ..." in my printf statement in the code from the OP.

      Part of the issue is I'm trying to adapt VB, C#, etc.. any code example I can find really - into Perl Win32::OLE.