Bulk Changing proxy addresses smtp: in Hybrid AD

Gabriel Raab 20 Reputation points
2025-05-19T20:53:53.7966667+00:00

https://learn.microsoft.com/en-us/answers/questions/1376686/bulk-add-email-alias-to-all-ad-user-accounts?source=docs

Following this link above, I am able to get the command to run but it misses the domain, and I get just a 'smtp:SamAccountName' in AD instead of the 'smtp:******@example2.com'

I had to modify the original, as we use firstinitial.lastname in our emails instead of first name. last name.

As such, I used '-Properties SamAccountName, proxyAddresses', instead of '-Properties EmailAddress, proxyAddresses'

Specifically:

($user in $users) {

$newAlias = $user.SamAccountName -replace '@example1.com', '@example2.com'



# Update the proxyAddresses attribute

Set-ADUser $user -Add @{proxyAddresses = "smtp:$newAlias"}

}

Here is the result:

Screenshot 2025-05-19 133520

What am I missing?

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,973 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2025-05-19T21:44:00.08+00:00

    I think you're confusing the SAMAccountName and UserPrincipalName properties. If I remember correctly, the SAMAccountName is limited to 20 characters. The UPN can be up to 1024 characters usually look like user.domain.xxx.

    Are you sure your SAMAccountName values have a domain name in them?

    If you're changing the proxy addresses you should be working with the contents of the proxyAddresses property. You should also note that the PRIMARY SMTP address has the "SMTP" protocol in upper case. Secondary smtp addresses have the protocol expressed in lower case. Also, be aware there may be other protocols in the proxy addresses (the proxyAddresses property is a multivalued property). Depending on the age of your AD and Exchange organization you may find X400, FAX, X500, SIP, EUM, and others in there! Who knows . . . you may even find old MS (Microsoft Mail) and CCMAIL protocols lurking in there. :-)


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.