31
Oct

Add Aliases in O365 using Powershell

Add users aliases in O365 (Powershell)

Things to Remember while adding aliases to MS O365 via PowerShell while running our CMD-lets

  • Prepare a user list for adding aliases in CSV format.
  • First Column will have primary email address and second will have aliases.
  • In the CSV, create header for primary email address as Mailbox and Alias email header will be named as NewEmailAddress
  • Create folder in C drive and name it as temp.
  • We are saving csv as aliases.csv
  • Connect the Exchnage powershell and Run below command. Click here to setup and connect Online powershell.

Adding aliases we can achieve by running the command in two ways but both will have the same result. The difference is working with PowerShell script and running it into Powershell ISE and another is via using Powershell CMD

First Method

By Importing everything from CSV to Variable named $user and then process our request. Also, you can save it as a PowerShell script like aliases.ps and then run it using windows Powershell ISE Or copy/paste the below code to the PowerShell console. Click here how to setup PowerShell for using O365.

Copy and past below CMD to Powershell or Copy/past it into notepad, save it as “Alias.ps” then open it in Powershell ISE. Click here how to connect PowerShell ISE for using O365.

$users = Import-csv ‘C:\temp\aliases.csv’
foreach($user in $users)
{
Set-Mailbox “$($user.Mailbox)” -EmailAddresses @{add=”$($user.NewEmailAddress)”}
}

Second Method

Below CMD will use to direct apply changes without using any variable. Copy the below command and past it to Powershell CMD. Connect power with exchange online (EXO) before past the below command.

Import-csv ‘C:\temp\aliases.csv’
foreach{
Set-Mailbox $_.Mailbox -EmailAddresses @{add=”$_.NewEmailAddress”}
}

Please share and Like if it helps you or Reply in comment if something issue missing.