Help creating a script to import CSV to update Global Address List

Copper Contributor



I hope someone can help.


I am trying to create a script that allows me to import and update a customer global address list with a CSV file that they have sent. This script when run would basically change there global address list to match this CSV file, this will be done monthly and I am not 100% how to create this.

7 Replies
What have you tried already? Did you start already with it? Or are you just asking for others to write it for you?
There is a lot to it, even though it's a simple operation. Does the list (from the client) ONLY contain additions to the GAL, or is it also removing members from the GAL? These are the things that need all the consideration when writing a script for it.

Sorry I don't know why I didn't post the script I have.


I'm just waiting to find out if the csv he is sending me has users that have been removed or if it is just additional users every time. If it is just additional users every time would the below script suffice? I understand if users need removing there would probably be more to it.


Import-Module ExchangeOnlineManagement

$UserCredential = Get-Credential

Connect-ExchangeOnline -Credential $UserCredential

$GAL = Get-GlobalAddressList -Identity "Default Global Address List"

$Members = Import-Csv -Path "C:\Temp\AddressListMembers.csv"

$Members | ForEach-Object {

         $Recipient = Get-Recipient $_.EmailAddress

         Add-AddressListMember -AddressList $GAL -Member $Recipient   





Yeah you're 100% right. I do have a script that I have put together below however if I imported the csv and the imported csv had some users that had been removed, it wouldn't remove these would it? It would only add?
I am waiting to hear back from the customer.
in that case you need to clear the GAL before uploading the new csv. But clearing a GAL is a big thing. i would prefer a new addresslist which is not containing any system generated members like mailbox users or shared mailbox users.
By the looks of the CSV. It is just external contacts. He sends this CSV every month and just adds a bunch of users on every time, I would assume that if I imported this it would import the additional users and just error on the users that are already there or am I wrong in saying that
Indeed error on what exists but no removal of missing