I thought I would share this with the community because I googled and googled and googled some more no one has wrote a simple few lines to accomplish this so this is my way of trying to help others with the same issue. Our company has gone through a domain change and we needed to add new SMTP setting for each user and distribution group. Here is how I did it. I am no expert so the code might be deemed rough it did produce the expected results.
Get-Distributiongroup | foreach-object {
$dg = Get-distributiongroup -Identity $_.Name
$email=$_.alias+"@NEWDOMAIN.com"
$_.emailAddresses += $email
Set-DistributionGroup -Identity $dg -EmailAddresses $_.emailAddresses -EmailAddressPolicyEnabled $true
Write-host -foregroundcolor green $dg has now had $Email added to thier SMTP
}
This does not set the Primary SMTP server all it does is add an additional email address to the group.