Create 100s of Email Aliases in Office 365

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#@, 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.


  1. Hello Jonathan,

    Thank you very much for this information. I am having an issue with defining the first variable.

    When I run the line Import-Csv C:alias.csv | ForEach-Object{ $name = $_.Name } and then run $name, only the last entry in the list of names shows, and therefore that is the only account that updates. Do you know how I can get the variable to store all of the values in the name column?

    Best regards,

    • Hi, Brian,

      These commands work for 1 account at a time. If you’re trying to update multiple users accounts from a TXT file all at once you have to use a Powershell script.

      Your import file should look like this:
      Name, ProxyAddresses
      user1, email1;email2;email3;email4
      user2, email1;email2;email3… etc

      Create a new TXT file with the following content (make sure to update the location of your import file):

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

      Save the txt file as import-alias.ps1 (a powershell script file) and run the script within Powershell by typing c:\import-aslias.ps1

      This will run the three commands for each line in the c:\alias.csv file.

      Just remember that these commands will REPLACE all addresses on an account, no append.

      Let me know how this works for you.

  2. Hello Jonathan,

    Thank you for the detailed response, it is much appreciated.

    I had tried something similar to this prior to my post but to no avail. I have tried the process you have outlined, but it looks like the variables are not being properly assigned. I receive the following error:

    Cannot bind argument to parameter ‘Identity’ because it is null.
    + CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Mailbox

    I will continue to plug away to see if I can figure out how to properly set the variables. If you have any suggestions, that would be awesome.

    Thanks for your help!


  3. Jonathan,

    Please disregard. Your information was perfect. My fat fingers are not. A typo was the root cause.

    Thanks again!!

Comments are closed.