Forum Discussion

euanvjc97's avatar
euanvjc97
Copper Contributor
Feb 01, 2023

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

Hi,

 

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

  • Feed-Jake's avatar
    Feed-Jake
    Copper Contributor
    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.
    • euanvjc97's avatar
      euanvjc97
      Copper Contributor
      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.
      • aterneuzen's avatar
        aterneuzen
        Brass Contributor
        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.
  • aterneuzen's avatar
    aterneuzen
    Brass Contributor
    What have you tried already? Did you start already with it? Or are you just asking for others to write it for you?
    • euanvjc97's avatar
      euanvjc97
      Copper Contributor

      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   

      }

      Disconnect-ExchangeOnline

       

      @aterneuzenaterneuzen 

Resources