Could I add more than 200 email contacts in the Default Global Address list by using powershell at once?

Kailin 1 Reputation point
2021-08-31T17:37:34.21+00:00

I got two questions about the Global Address list here:

  1. I get more than 200 email contacts and want to add into the Default Global Address list at once by using PowerShell . But it only allowed me to add 40 contacts each times which not efficiency. Is there any way to do that at once?
  2. Does the GAL allows the duplicate email address? Since we have clients that have several members share one email. So If there's any way that could make Outlook 2016 or GAL allow to create duplicate email address?

Thank you!

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,870 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,331 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,352 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 44,621 Reputation points
    2021-08-31T18:23:40.217+00:00

    You should be able to add as many contacts to the Active Directory as you want using the New-Mailcontact cmdlet.

    The Global Address List is managed by Exchange server. If a mail-enabled object isn't showing up in the GAL it may be because it's been hidden from the GAL. If that's the case you can use the Set-Mailcontact cmdlet and the HideFromGlobalAddressList parameter to allow its inclusion in the GAL.

    The GAL is updated only periodically, so don't expect it to show up immediately.

    The GAL just uses what's in the AD. Exchange shouldn't allow the same email address to be used in more than one mail- or mailbox-enabled object. Email addresses must be unique.

    0 comments No comments

  2. Limitless Technology 39,336 Reputation points
    2021-08-31T19:48:15.68+00:00

    Hello,

    I don`t think this will be an easy one. To bulk import contacts, one of the efficient ways is to use PowerShell. Here are the instructions on how to use PowerShell for importing multiple contacts using a .csv file

    Gathering Contacts

    1.Create a contact CSV (comma-separated value) file containing the following headers.

    ExternalEmailAddress

    Name

    FirstName

    StreetAddress

    City

    StateorProvince

    PostalCode

    Phone

    MobilePhone

    *Type in precisely as mentioned above.

    2.Please note that you must provide an email address [ExternalEmailAddress] for each contact. If any of the employees do not have an email address, exclude those records from this list because those cannot be processed and imported.

    You must fill out these two mandatory columns for each contact.

    ExternalEmailAddress
    Name
    *The other columns are optional. If any column is left blank, it will not be imported into the GAL.

    Code execution and its explanation:

    PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned (Setting Up Execution Policy and set it RemoteSigned).

    Execution Policy Change

    The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at

    http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?

    [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y

    (Set it to Yes or Yes to All )

    PS C:\Windows\system32> $UserCredential=Get-Credential (Provide the server administrator credentials)

    PS C:\Windows\system32> $s=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ********************************** -credential $UserCredential -Authentication Basic -AllowRedirection

    PS C:\Windows\system32> import-PSSession -session $s

    (Importing the session so that all the commands like New-MailContact, New-MailBox, etc. controls can operate on cmd script)

    creating the system pop-up dialog box for importing the CSV file. Please note ‘param’ might show warning messages, but you can ignore it.

    param(  
    
        [Parameter(ValueFromPipeline=$true,HelpMessage="Enter CSV path(s)")]  
    
        [String[]]$Path = $null  
    
    )  
    
    if($Path -eq $null) {  
    
        Add-Type -AssemblyName System.Windows.Forms  
    
        $Dialog = New-Object System.Windows.Forms.OpenFileDialog  
    
        $Dialog.InitialDirectory = "$InitialDirectory"  
    
        $Dialog.Title = "Select CSV File(s)"  
    
        $Dialog.Filter = "CSV File(s)|*.csv"          
    
        $Dialog.Multiselect=$true  
    
        $Result = $Dialog.ShowDialog()  
    
        if($Result -eq 'OK') {  
    
            Try {  
    
                $Path = $Dialog.FileNames  
    
            }  
    
            Catch {  
    
                $Path = $null  
    
                Break  
    
            }  
    
        }  
    
        else {  
    
            #Shows upon cancellation of Save Menu  
    
            Write-Host -ForegroundColor Yellow "Notice: No file(s) selected."  
    
            Break  
    
        }  
    
        $Date = Get-Date  
    
    Write-Host "You input:'$Path' on '$Date'"  
    
    }  
    

    Display the CSV file imported.

    Import-Csv $Path

    Uploading the imported CSV file.

    Import-Csv $Path |%{New-MailContact -Name $.Name -DisplayName $.Name -ExternalEmailAddress $.ExternalEmailAddress -FirstName $.FirstName -******** $_.LastName}

    Please note the following:

    1. Marked in red (Error message) may come if the contacts are already added in the GA, or there is some error in the CSV file.
    2. In our case, we have added only ExternalEmailAddress and Name. In order to customize more inputs, please modify the command as follows.

    Import-Csv $Path |%{New-MailContact -Name $.Name -DisplayName $.Name -ExternalEmailAddress $.ExternalEmailAddress -FirstName $.FirstName -LastName $.LastName -StreetAddress $.StreetAddress} and so on.

    Syntax:

    -ExternalEmailAddress $_.(CSV File Coloumn Name)

    -Name $_.(CSV File Coloumn Name)

    -FirstName $_.(CSV File Coloumn Name)

    -LastName $_.(CSV File Coloumn Name)

    -StreetAddress $_.(CSV File Coloumn Name)

    -City $_.(CSV File Coloumn Name)

    -StateorProvince $_.(CSV File Coloumn Name)

    -PostalCode $_.(CSV File Coloumn Name)

    -Phone $_.(CSV File Coloumn Name)

    -MobilePhone $_.(CSV File Coloumn Name)

    1. Other parameters which can be used with New-MailContact cmdlet are as follows:

    New-MailContact

    -Name <String>

    -ExternalEmailAddress <ProxyAddress>

    [-Alias <String>]

    [-ArbitrationMailbox <MailboxIdParameter>]

    [-Confirm]

    [-DisplayName <String>]

    [-DomainController <Fqdn>]

    [-FirstName <String>]

    [-Initials <String>]

    [-LastName <String>]

    [-MacAttachmentFormat <MacAttachmentFormat>]

    [-MessageBodyFormat <MessageBodyFormat>]

    [-MessageFormat <MessageFormat>]

    [-ModeratedBy <MultiValuedProperty>]

    [-ModerationEnabled <Boolean>]

    [-OrganizationalUnit <OrganizationalUnitIdParameter>]

    [-OverrideRecipientQuotas]

    [-PrimarySmtpAddress <SmtpAddress>]

    [-SendModerationNotifications <TransportModerationNotificationFlags>]

    [-UsePreferMessageFormat <Boolean>]

    [-WhatIf]

    [<CommonParameters>]

    For more information on parameters, please refer to the link:

    https://learn.microsoft.com/en-us/powershell/module/exchange/new-mailcontact?view=exchange-ps

    Contacts are now available on the admin console.

    You can also copy and paste the complete code on windows PowerShell ISE and save it as .ps1 file and run the same.

    Set-ExecutionPolicy RemoteSigned

    $UserCredential=Get-Credential

    $s=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ********************************** -credential $UserCredential -Authentication Basic -AllowRedirection

    import-PSSession -session $s

    param(  
    
        [Parameter(ValueFromPipeline=$true,HelpMessage="Enter CSV path(s)")]  
    
        [String[]]$Path = $null  
    
    )  
    if($Path -eq $null) {  
    
        Add-Type -AssemblyName System.Windows.Forms  
    
        $Dialog = New-Object System.Windows.Forms.OpenFileDialog  
    
        $Dialog.InitialDirectory = "$InitialDirectory"  
    
        $Dialog.Title = "Select CSV File(s)"  
    
        $Dialog.Filter = "CSV File(s)|*.csv"          
    
        $Dialog.Multiselect=$true  
    
        $Result = $Dialog.ShowDialog()  
    
        if($Result -eq 'OK') {  
    
            Try {  
    
                $Path = $Dialog.FileNames  
    
            }  
    
            Catch {  
    
                $Path = $null  
    
                Break  
    
            }  
    
        }  
    
        else {  
    
            #Shows upon cancellation of Save Menu  
    
            Write-Host -ForegroundColor Yellow "Notice: No file(s) selected."  
    
            Break  
    
        }  
    
        $Date = Get-Date  
    
    Write-Host "You input :'$Path' on '$Date'"  
    
    }  
    

    Write-Host "Displaying Content of the .CSV File. Please remember (ExternalEmailAddress & Name are two default fields to add contacts to exchange and has to be the first two-column). ExternalEmailAddress

    Name

    FirstName

    LastName

    StreetAddress

    City

    StateorProvince

    PostalCode

    Phone

    MobilePhone "

    Import-Csv $Path

    Import-Csv $Path |%{New-MailContact -Name $.Name -DisplayName $.Name -ExternalEmailAddress $.ExternalEmailAddress -FirstName $.FirstName -LastName $_.LastName}

    More Information regarding the topic:

    https://learn.microsoft.com/en-us/exchange/address-books/address-lists/address-lists

    https://learn.microsoft.com/en-us/exchange/email-addresses-and-address-books/address-lists/address-lists?view=exchserver-2019

    https://learn.microsoft.com/en-us/exchange/address-books/address-lists/manage-address-lists

    Regards,

    0 comments No comments

  3. Joyce Shen - MSFT 16,641 Reputation points
    2021-09-01T06:43:49.953+00:00

    Hi @Kailin

    I agree with the reply above from RichMatheisen-8856, mail contacts are included in the Exchange Global Address List (GAL) and Offline Address Book (OAB)

    So we could use the method introduced in this article to bulk import mail contacts to your server: Exchange PowerShell: How to Bulk Import/Create Mail Contacts

    For your second question, I would suggest you read this article: Preventing duplicate SMTP addresses on Exchange
    SMTP addresses need to be unique within your Exchange organization, and we should avoid duplicate addresses in Exchange server

    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments