0

I am not exchange admin but just a common user. I believe we are using Exchange 2019 and the address book (is it called GAL?) is saved in server side. I can open and search it via my Outlook interface.

Beside Outlook program I have access to PowerShell. I tested $Outlook = NEW-Object -comobject Outlook.Application and I can successfully get the object.

I want to export the address book (users and groups) into csv by UI or PowerShell. How can I do it?

Mark
  • 283
  • 3
  • 22
  • What have you searched for / used? What happened? Post your code. SO has rules: [Provide MRE](https://stackoverflow.com/help/minimal-reproducible-example) --- [How to ask](https://stackoverflow.com/help/how-to-ask) --- [Don't ask](https://stackoverflow.com/help/dont-ask) --- [Proper Topic](https://stackoverflow.com/help/on-topic) --- [Why not upload images of code/errors?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) --- [format your post properly](https://stackoverflow.com/help/formatting) – postanote Mar 16 '21 at 07:07
  • 1
    Why are you trying to export the internal corporate GAL? There are legal reasons/ PII-Data policies/risk management/security reasons organizations/enterprises block this action from normal users. You can export contacts from your Outlook client. Why are you trying to automate this if this is just for you? What you'd do is the same as you would do in the Outlook GUI. Use Outlook to create a macro that does this, and leverage that code from PowerShell. [There are many articles showing how to export Outlook contacts](https://duckduckgo.com/?q=%27Outlook+export+address+book%27&t=h_&ia=web). – postanote Mar 16 '21 at 07:16
  • 1
    [Just as there are many articles covering GAL export](https://duckduckgo.com/?q=%27Outlook+export+address+book%27+powershell&t=h_&ia=web). Again, Exchange Admin / Org rights/permissions will block this. Regardless of whatever tools you are trying to use., – postanote Mar 16 '21 at 07:19
  • @postanote Maybe I missed something. I can only export my local contact not the address book for my organization. – Mark Mar 16 '21 at 07:59
  • hmm, sorry to ask, but if I can read all the contact my scrolling up and down in address book, then I should not violate any rules by export the same thing for personal use? – Mark Mar 16 '21 at 08:04
  • Correct. You need to have access to the Exchange cmdlets to hit the GAL directly. That means you need to be on the Exchange server, directly (physically or RDP) or indirectly (via Explicit/Implicit remoting), and you must have permission to do so. – postanote Mar 16 '21 at 08:04
  • Contacts are just a folder in Outlook. SO, using Outlook COM, you can access those and do as you will. [There are lots of articles all over the web](https://duckduckgo.com/?q=%27powershell+export+outlook+contacts+to+csv%27&t=h_&ia=web) and Youtube videos showing how to use PowerShell and Outlook to do stuff with/ to Outlook. – postanote Mar 16 '21 at 08:06
  • @postanote maybe I should not use the term GAL. I only need to export what I see in my Outlook. – Mark Mar 16 '21 at 08:08
  • Correct. Then the links provided will get you there. – postanote Mar 16 '21 at 08:15
  • You'd probably be better off working with AD – Abraham Zinala Mar 16 '21 at 13:41
  • @AbrahamZinala I have tried `get-Aduser - properties *`. However some attributes like Officelocation are stored in exchange only and not sync to AD. – Mark Mar 17 '21 at 03:20
  • @Mark, using ADSI is what youd want to work with if youre going to stick with powershell. Keep in mind that its not user friendly at all but, it can definitely get what youre after. – Abraham Zinala Mar 17 '21 at 15:06

1 Answers1

1

You can automate Outlook from PowerShell to get all the required information. The NameSpace.GetGlobalAddressList method returns an AddressList object that represents the Exchange Global Address List. GetGlobalAddressList supports only Exchange servers. It returns an error if the Global Address List is not available or cannot be found. It also returns an error if no connection is available or the user is set to work offline.

Take a look at the following pages for more information and sample code (VBA, but the Outlook object model is common for all kind of programming languages):

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Your reference is very close to what I need. I am able to loop start thru entire GAL e.g. `For i = 1 To outlEntry.Count` but it is too big in my case. Do you know how can I narrow down the looping scale? – Mark Mar 18 '21 at 02:52