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, EmailAddressesEnd of the page 🎉
You have reached the end of the page. You can select a category, share this post on X, LinkedIn and Reddit or return to the blog posts collection page. Thank you for visiting this post.
- Azure Master Class (12)
- Azure Virtual Desktop (20)
- Flying (15)
- Intune (5)
- Microsoft 365 (12)
- Microsoft Azure (29)
- Microsoft Defender XDR (4)
- Microsoft Entra (9)
- Networking (5)
- Powershell (19)
- Uncategorized (1)
- Windows 365 (3)
- Windows Server (12)
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/
The terms and conditions apply to this post.
Page visitors: No page-counter data available yet.
1 Comment
Michaeltiday · June 27, 2025 at 13:18
Thanks, exactly what i needed