Forum Discussion

IrvanR's avatar
IrvanR
Copper Contributor
Oct 12, 2024

change the primary address (prefix) distribution list group

change the prefix on the primary address distribution list group

how to bulk change primary smtp address distribution list group (before @ / prefix) with powershell?

can use csv file?

 

if possible, what is the csv format and how is the script?

 

please help, thank you.

  • IrvanR You could use something like:

     

     

    #Install module and connect
    Install-Module ExchangeOnlineManagement
    Connect-ExchangeOnline
    
    #Loop through csv file and change primary smtp
    foreach ($row in Import-Csv -Path C:\data\dl.csv -Delimiter ';') {
        try {
            Set-DistributionGroup -Identity $row.GroupName -PrimarySmtpAddress $row.Email -ErrorAction Stop
            Write-Host ("Updated {0}" -f $row.GroupName)
        }
        catch {
            Write-Warning ("Error updating {0}" -f $row.GroupName)
        }
    }

     

     

    CSV looks like:

    GroupName;Email
    Testdl1;email address removed for privacy reasons
    Testdl2;email address removed for privacy reasons

     

     

  • IrvanR You could use something like:

     

     

    #Install module and connect
    Install-Module ExchangeOnlineManagement
    Connect-ExchangeOnline
    
    #Loop through csv file and change primary smtp
    foreach ($row in Import-Csv -Path C:\data\dl.csv -Delimiter ';') {
        try {
            Set-DistributionGroup -Identity $row.GroupName -PrimarySmtpAddress $row.Email -ErrorAction Stop
            Write-Host ("Updated {0}" -f $row.GroupName)
        }
        catch {
            Write-Warning ("Error updating {0}" -f $row.GroupName)
        }
    }

     

     

    CSV looks like:

    GroupName;Email
    Testdl1;email address removed for privacy reasons
    Testdl2;email address removed for privacy reasons

     

     

    • IrvanR's avatar
      IrvanR
      Copper Contributor

      Yes, I have been able to bulk change the prefix of the primary email address group using the script and csv format you provided. Thank you

    • IrvanR's avatar
      IrvanR
      Copper Contributor

      I have another question Harm_Veenstra, Can this script also be used to bulk update SMTP address DL group in Exchange Server 2019?

      • Yes, you can run it on a Exchange server, too. Just remove the first four lines 

Resources