locked
Adding secondary smtp addresses to Distribution Groups RRS feed

  • Question

  • Hello,

    I've been given the task of creating quite a few distribution groups, which I don't fancy doing one by one. I've got a working command (Below) but what do I need to include to add secondary smtp addresses which I have a column set up in the .csv file as 'SecondaryAddress'

    Import-CSV "C:\test.csv" | ForEach {new-DistributionGroup -Name $_.Name -Alias $_.Alias -PrimarySmtpAddress $_.PrimaryAddress -Type $_.Type -OrganizationalUnit $_.OU}

    Any help is appreciated! 

    Thanks,

    Ash


    Monday, March 21, 2016 4:50 PM

Answers

  • You will have to add a couple of more lines to the script.  The cmdlet, New-DistributionGroup, doesn't support being able to add additional email addresses beyond the primary email address.

    $Distros = import-csv c:\test.csv
    
    foreach ($d in $distros)
    {
        $DistroName = $d.name
        $group = get-adgroup $distroname -properties proxyaddresses
    
        set-adgroup $group -add @{proxyaddresses="smtp:" + "your seconday email address here"}
    }


    • Edited by Xecros Monday, March 21, 2016 5:21 PM
    • Proposed as answer by Elaine Jing Tuesday, March 22, 2016 9:04 AM
    • Marked as answer by Elaine Jing Thursday, April 7, 2016 7:01 AM
    Monday, March 21, 2016 5:21 PM
  • Set-DistributionGroup -Name $_.Name -EmailAddresses $_.EmailAddress1,$_.EmailAddress2 ...

    See: https://technet.microsoft.com/en-us/library/bb124955(v=exchg.160).aspx


    \_(ツ)_/

    • Proposed as answer by Elaine Jing Tuesday, March 22, 2016 9:04 AM
    • Marked as answer by Elaine Jing Thursday, April 7, 2016 7:01 AM
    Monday, March 21, 2016 5:23 PM

All replies

  • You will have to add a couple of more lines to the script.  The cmdlet, New-DistributionGroup, doesn't support being able to add additional email addresses beyond the primary email address.

    $Distros = import-csv c:\test.csv
    
    foreach ($d in $distros)
    {
        $DistroName = $d.name
        $group = get-adgroup $distroname -properties proxyaddresses
    
        set-adgroup $group -add @{proxyaddresses="smtp:" + "your seconday email address here"}
    }


    • Edited by Xecros Monday, March 21, 2016 5:21 PM
    • Proposed as answer by Elaine Jing Tuesday, March 22, 2016 9:04 AM
    • Marked as answer by Elaine Jing Thursday, April 7, 2016 7:01 AM
    Monday, March 21, 2016 5:21 PM
  • Set-DistributionGroup -Name $_.Name -EmailAddresses $_.EmailAddress1,$_.EmailAddress2 ...

    See: https://technet.microsoft.com/en-us/library/bb124955(v=exchg.160).aspx


    \_(ツ)_/

    • Proposed as answer by Elaine Jing Tuesday, March 22, 2016 9:04 AM
    • Marked as answer by Elaine Jing Thursday, April 7, 2016 7:01 AM
    Monday, March 21, 2016 5:23 PM
  • that works to, and is more efficient.  

    either way works, I prefer directly modifying the proxyaddresses attribute, particularly when i need to change the primary email address

    Monday, March 21, 2016 5:26 PM
  • Hello,

    Thanks for the response.

    I believe that command is run after I create the groups. Is there way to do it all in one command, ideally adding onto the one I've mentioned above.

    Thanks,

    Ash

    Tuesday, March 22, 2016 1:17 PM
  • You can just add to the ForEach-Object loop.

    Tuesday, March 22, 2016 1:33 PM