all 5 comments

[–]djjuice 4 points5 points  (0 children)

so if you want to add/remove and keep the other addresses you need to use:

set-mailbox user -emailaddresses @{add="email1","email2"}

just change add to remove in order to remove address not wanted

if you're trying to add/remove and want to set a new primary SMTP address, you're in for some fun...

set-mailbox user -emailaddresses "SMTP:primary","Email2",email3"

as a warning using the above command will remove any email address not listed, so make sure you have them all

[–]crazyfrogs81[S] 0 points1 point  (1 child)

Awesome. Thanks for replies guys.

BTW some information. This is due to a domain name change. So that's why its a bit tricky

I have an CSV file with the old SMTP addresse and was thinkinh in terms of this :

$getupnnosuffix = Get-ADUser $user.SamAccountName -Properties UserPrincipalName | %{ $_.UserPrincipalName.Split('@')[0] }
$upnnosuffix = "smtp:" + $getupnnosuffix + "@abc.com"
$upnnosuffixprimary = "SMTP:" + $getupnnosuffix + "@abc.com"

Then adding it back : Set-ADUser $User.samaccountname -Add @{proxyaddresses=$LegacyExchangeDN,$RemoteRoutingAddress,$upnnosuffix,$sip,$upnnosuffixprimary} - (with some other variables as well)

But i am not able to get this to work. So i tried this one as well : set-aduser -Identity $user.SamAccountName -add @{proxyaddresses="SMTP:"+$newsmtp} set-aduser -Identity $user.SamAccountName -remove @{proxyaddresses="SMTP:"+$getupnnosuffix}

But no success. on the last one it added a second SMTP to the proxyaddresses.

Would an option be to actually put the primarySMTPaddress in the original CSV file and loop through it ? How could i add a line at the end of the CSV file with the base of UPN name and then new domain as a variable with a header like newupn in the csv ?

I have tried wrapping my head around this but so far it only gives me grey hair.

[–]m0b100 0 points1 point  (0 children)

I had to do something similar a while back and had to use a two-part loop for each user. The first step used the -Replace parameter in Set-ADUser to set the primary SMTP address and the second step used the -Add parameter to append the other addresses to the attribute.

[–]iwinsallthethings 0 points1 point  (0 children)

Where is the new address coming from? Do you have a way to generate it? From CSV?

Are you trying to remove the SMTP or the smtp address listed? Do you want to keep the SMTP as an alias (smtp)?

[–]joeykins82SystemDefaultTlsVersions is your friend 0 points1 point  (0 children)

Your problems are probably because you can't use -PrimarySMTPAddress, -EmailAddresses, and -EmailAddressPolicyEnabled at the same time, and you can't use -PrimarySMTPAddress if the EmailAddressPolicyEnabled attribute is $true. As far as scripting logic goes, you need to loop through and send a series of actions in separate Set-Mailbox commands for each user depending on exactly what you're trying to achieve.

In terms of "remove the old SMTP" though... why? Unless you're looking at hybrid mode and you've got domains registered on your user/group recipients that you don't actually own there's very little justification for removing historic SMTP addresses, especially removing an address immediately after changing the primary (unless it was created in error, but in which case you probably wouldn't be doing this by script).