Occasionally I receive the request to have hundreds of email aliases added to a user’s Office365 email address – typically for software product testing. Creating the aliases using the web interface would be tedious and time consuming. Luckily we have Powershell, which makes this task infinitely easier.

Step 1 – Create the aliases

Typically the aliases requested are in the format username#@ domain.com, where # is a number. We’ll use Excel to create a formula that will allow you to generate the number of aliases needed. The columns should be:

alias, number, domain, and the formula =A1&B1&”@”&C1

The formula will combine the first 3 columns into a single email address. You can then fill in the numbers by dragging the columns down. Once you have all of the rows populated copy and paste the email addresses into Notepad++

Step 2 – Create the alias CSV file in Notepad++

On the first line of Notepad++ add the following:

Name, ProxyAddresses,

This will set the column headers when importing with Powershell

Paste the email addresses from Excel into Notepad++ on the next line. This will put all of the email addresses on their own lines. You now need to get them all on the same line, with ; between each address.

  1. Put the cursor at the first email address and press Ctrl-H to bring up find-replace
  2. Select Regular Expression at the bottom
  3. In the find field type \r\n (this will find all line breaks)
  4. In the replace type ; (this will replace all line breaks with ; )
  5. Run the find-replace
  6. Add the username followed by a , to the front of that line
  7. Make sure there is no ; at the end of the line – the last email address should have nothing after it. Make sure there are no extra lines at the end of the document.
  8. Save the document as c:aliases.csv

NOTE: You must add any existing aliases already assigned to the account to the line of aliases, separated by ; – this command will replace all aliases, not add additional ones.

Step 3 – Importing the aliases

After connecting Powershell to Office365 run the following three commands. The first command sets the variable $name to the alias, the second command sets the variable $proxy to the list of email addresses. The final command sets the email addresses to the account.

Note: You can make sure the variables have the correct data by typing the variable at the command prompt in Powershell before running the third command.

  1. Import-Csv C:alias.csv | ForEach-Object{ $name = $_.Name }
  2. Import-Csv C:alias.csv | ForEach-Object{ $proxy = $_.ProxyAddresses -split ‘;’}
  3. Set-Mailbox -Identity $name -EmailAddresses @{add= $proxy}

Once completed you should be able to see all of the aliases by running the following two commands:

  1. $Mailbox = Get-Mailbox -Identity $name
  2. ForEach ($i in $Mailbox.EmailAddresses) {Write-Host $i -NoNewline “`b, “}

You should now see all of the aliases.

You can read other great technology articles like this one on the Project Leadership Associates Blog