Set a domain alias for every user in Microsoft 365
Categories:
Sometimes, we add a new domain to Microsoft 365 and we want to have a domain alias for multiple or every user.
Logging in Exchange Online Powershell
To configure a alias for every user, we need to login into Exchange Online Powershell:
Connect-ExchangeOnlineIf you don’t have the module already installed on your computer, run the following command on an elevated window:
Install-Module ExchangeOnlineManagementSource: https://www.powershellgallery.com/packages/ExchangeOnlineManagement/3.7.2
Adding the 365 domain alias to every user
After succesfully logged in, run the following command:
$users=Get-Mailbox | Where-Object{$_.PrimarySMTPAddress -match "justinverstijnen.nl"}Here our current domain is “justinverstijnen.nl” but let’s say that we want to add “justinverstijnen.com”. Run the following command to do this:
foreach($user in $users){Set-Mailbox $user.PrimarySmtpAddress -EmailAddresses @{add="$($user.Alias)@justinverstijnen.com"}}Now we have added the alias to every user. To check if everything is configured correctly, run the following command:
$users | ft PrimarySmtpAddress, EmailAddresses
End of the page 🎉
You have reached the end of the page. You can navigate through other blog posts as well, share this post on X, LinkedIn and Reddit or return to the blog posts collection page. Thank you for visiting this post.
If you think something is wrong with this post or you want to know more, you can send me a message to one of my social profiles at: https://justinverstijnen.nl/about/
If you find this page and blog very useful and you want to leave a donation, you can use the button below to buy me a beer. Hosting and maintaining a website takes a lot of time and money. Thank you in advance and cheers :)
The terms and conditions apply to this post.