Create G Suite Aliases in Bulk with this Script

create gmail email aliases in builk- script

There might be scenarios where you want to create email aliases for multiple users and doing this one by one takes a lot more time.

There are tools in the market that you can use to create G Suite email aliases in bulk, however they’re either expensive or complex to setup.

So, I’ll show you how you can create email aliases in bulk by running a script in your G Suite admin console.

Step-by-step video tutorial

paste script then save file
Play Video

Here is a video guide where I take you through from start to finish on how to quickly create hundreds or even thousands of email aliases in just minutes using this script.

1. Create new Google sheet

So first step is for you to create a new Google spreadsheet. Then rename your sheet to ‘Create Alias‘.

This is because the script will be looking for a spreadsheet with the same exact name, so it is important you copy and paste the name correctly.

2. Go to script editor

Next, from the new sheet you just created, go to ‘Tools‘ then click on ‘Script editor‘ to create a new script.

3. Copy and paste script

Now copy and paste the following script into your script file. After pasting the script, don’t forget to save where you get also get prompted to provide project name.

function createrAlias() {
  var ss = SpreadsheetApp.getActive()
  var sheet = ss.getSheetByName("Create Alias")
  var values = sheet.getDataRange().getValues()
  var fileArray = [["Alias Creation Status"]]
  for(i=1; i <values.length; i++)
    var userKey = values[i][0]
    var aliasId = values[i][1]

      var status = "Alias Not Created"
      var status = AdminDirectory.Users.Aliases.insert({"primaryEmail": userKey,"alias": aliasId}, userKey)
      if (status != "Alias Not Created"){

        status = "Alias Created Successfully"


    catch (e) {

      var status = e.message
  var range = sheet.getRange(1, 3, fileArray.length, 1).setValues(fileArray)

Script overview

So, here is an overview of how the script essentially works:

  1. The script will look for two values from the first two columns of the spreadsheet.
  2. The first column should be ‘User key”, which is the user’s primary email address.
  3. The second column is a user’s alias id which is also the nickname.
  4. In the third column, the script will report whether or not an alias was successfully created.

4. Prepare spreadsheet

As explained above, you will need to provide two columns with the first column being a user’s primary email address and in the second, an alias ID you want to create for that specific user.

In my case, I am creating aliases for just one email address however, you can create for several different users be it 500 or 1000 different email IDs whichever you like.

5. Enable ‘Admin Directory API’

Now before you can run the script, you need to do one more thing. That is to enable Admin Directory API.

So to enable Admin Directory API, go back to the script page, click on ‘Resources‘ then from  the drop down menu click on ‘Advanced Google services‘ option.

Toggle the on-off button to enable Admin directory API. Then, click on ‘Google API Console’ link.

On the next screen, click on ‘Enable APIS and Services’ button

Now, search for ‘admin sdk’ and then click on ‘Admin SDK‘ from the results

Click on ‘Enable‘ button to turn on admin SDK.

After enabling admin SDK, you then come back to ‘Advanced Google services‘ page then click on ‘OK’ button then Google will update the changes.

6. Run script

Now you’re all set and ready to run your script. Click on the ‘play’ button to execute the script.

Because you’re running the script for the first time, Google will ask you to give permissions using your account.

All you have to do is choose an account (if you have multiple account signed in) then click on ‘Allow’ button to give your project permissions to services such as spreadsheet, and user management.

Now the script will run for a few seconds or more depending on the number of email aliases on the spreadsheet.

So, you should see a script response on the third column of the spreadsheet after aliases have successfully been created.

entity already exists - script

The script will also be able to notify you if an alias you’re trying to create already exists with ‘Entity already exists‘ message response.

That’s all!

That’s all to it. You can quickly create hundreds of email aliases by simply running a Google apps script.

I hope you found it helpful, for questions and comments, please leave them in the comment section below and I will be more than glad to help.


16 thoughts on “Create G Suite Aliases in Bulk with this Script”

    1. Thank you, Glad I could help.

      BTW – I just added “Alias Manager” module to “Ok Goldy” google sheet add on, so now you can add, delete, export G Suite user aliases in bulk right from your Google Sheet without any script.

  1. A user’s alias is an alternate email address that uses the same mailbox used by the user’s primary email address. A user alias can be associated with a different account domain than that domain used by the user’s primary email address.

  2. David Patterson

    Thanks for providing the detailed instructions. Unfortunately, like LARS, I am getting the error “TypeError: Cannot call method “getDataRange” of null. (line 6, file “Code”)”. My sheet IS named Create Alias. Debug shows the var sheet has a null value, so appears the ss.getSheetByName(“Create Alias”) is not working. Unlike LARS, I cannot figure out what I’m doing wrong. I wish LARS had posted what he or she figured out.

    1. Hi David – When you say you named your sheet “Create Alias”, did you mean the name which appears at the bottom of the sheet (where you have option to add 1000 rows? if not, please name it there.

      Also, I have recently published a Google sheet add on to perform bulk G Suite operations like managing users, groups and members in bulk, and I will add alias management to it in next version.

      If thats of interest, You may visit to learn how it works.

  3. Hello Goldy

    I am getting “”AdminDirectory” is not defined” as the error message. Does it need any modification?

  4. Hi Goldy, Thanks for this. I’m getting an error ‘Resource Not Found: userKey’. Followed all directions to the letter, any thoughts on what the problem may be? I have already logged out of gmail and back in to assure I’m in my account that I am using as my primary id.

  5. i get an error when starting the script: Cannot call method “getRange” of null. (line 0)
    It has to do something with line 6 in the script: var values = sheet.getDataRange().getValues()

    I just dont see what it is? Can you help?

      1. Still have the same error:

        {createrAlias:function createrAlias() {var ss = SpreadsheetApp.getActive();var sheet = ss.getSheetByName(“Create Alias”);var values = sheet.getDataRange().getValues();var fileArray = [[“Alias Crea…

        ypeError: Can not call method getDataRange from null. (line 6, file ‘Code’)

  6. Pingback: G Suite Session Timeout - Control session timeout in G Suite

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.