Bulk add alias name by using script

Bulk add alias name by using script

Before we can run the script, we need to connect to exchange online powershell.

Connect to exchange online powershell with MFA

Set-ExecutionPolicy RemoteSigned

* Install exchange online module

Install exchange online module
– Install-Module -Name ExchangeOnlineManagement
* execute the command in PowerShell
– Update-Module -Name ExchangeOnlineManagement
– Get-Module ExchangeOnlineManagement
– Import-Module ExchangeOnlineManagement
* connect to Exchange Online
* domain.onmicrosoft.com is Ternant’s name
Connect-ExchangeOnline -UserPrincipalName user@domain.com -DelegatedOrganization domain.onmicrosoft.com
————- add alais name to email ————–

Import-CSV “D:\RemoveAlias.csv” | ForEach {Set-Mailbox $_.OldEmailAddress -EmailAddresses @{add=$_.NewEmailAddress}}

————- remove alais name from email ————
Import-CSV “D:\RemoveAlias.csv” | ForEach {Set-Mailbox $_.OldEmailAddress -EmailAddresses @{Remove=$_.NewEmailAddress}}

OldEmailAddress replace with the UserPricipleName

NewEmailAddress replace with the alias name that we want to remove
———————–remove domain————

create alias with csv file


Change UPN
4.1 Install AzureAD and AzureAd Preview modules
– Install-Module AzureAD
– Install-module AzureADPreview
4.2 connect to Azure AD
– Connect-AzureAD
4.3 change UPN
– Import-CSV “C:\test\channge_upn.csv” | Foreach { Set-AzureADUser -ObjectID $_.UserPrincipalName -UserPrincipalName $_.NewUPN }

  1. Delete Alais
    *Create CSV file
    Run the below script for removing alias name

Import-CSV “C:\test\remove_alias.csv” | ForEach {Set-Mailbox $_.OldEmailAddress -EmailAddresses @{Remove=$_.NewEmailAddress}}

Leave a Reply

Your email address will not be published.