Share via


Adding secondary smtp addresses to Distribution Groups

Question

Monday, March 21, 2016 4:50 PM

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

All replies (5)

Monday, March 21, 2016 5:21 PM ✅Answered | 1 vote

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"}
}

Monday, March 21, 2016 5:23 PM ✅Answered | 1 vote

Set-DistributionGroup -Name $_.Name -EmailAddresses $_.EmailAddress1,$_.EmailAddress2 ...

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

\(ツ)_/


Monday, March 21, 2016 5:26 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


Tuesday, March 22, 2016 1:17 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:33 PM

You can just add to the ForEach-Object loop.