We use Google apps for enterprise, and I want to build an intranet, based on the Google sites intranet template

In the Directory area, I want that the list will be updated from my contact/company list directory.

Is it possible?

2 Answers 2


The following code retrieves the users, present within the Google Apps Domain:

function doGet() {
  var app = UiApp.createApplication(); 

  var users = UserManager.getAllUsers();  
  var flexTable = app.createFlexTable().setBorderWidth(1);

  for (var i=0, len=users.length; i<len; i++) {
    var user = users[i];
    flexTable.setWidget(parseInt(i), 0, app.createLabel(user.getGivenName()
      + ' ' + user.getFamilyName()));
    flexTable.setWidget(parseInt(i), 1, app.createLabel(user.getEmail()));


  return app;

Add this script, via the Google Apps Script gadget, to your page and the people will appear. See working example: domain users by script

There are however some prerequisites:

  1. Be an administrator
  2. Enable the provisioning API: dashboard/domain settings/user settings

You can also use a script within a spreadsheet and display the users in a spreadsheet:

function getdomainUsers() {
  // set spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // set sheet
  var sheet = ss.getSheets()[0];

  // set range
  var range = sheet.getRange(2, 1, sheet.getLastRow(), 2);

  // clear range

  // retrieve all users and create array
  var users = UserManager.getAllUsers(), auserInfo = new Array();  

  // itterate through users  
  for (var i=0, len=users.length; i<len; i++) {
    // instantiate user
    var user = users[i];

    // add info to array
    auserInfo.push([user.getGivenName() + ' ' + user.getFamilyName(),user.getEmail()]);

  // set values to sheet

Set a trigger on the script, to refresh the users for lets say every 12 hours. An administrator needs to prepare the sheet once. See working example: domain users by spreadsheet

  • First script doesn't return results. can you confirm its working please?
    – Saariko
    Nov 26, 2012 at 19:08
  • See modified answer. I've added working examples. One based on a stand alone script and the other one via a spreadsheet. Nov 26, 2012 at 21:13

Note: Apparently the Domain Service "...was deprecated on May 15, 2014, and will be turned off on November 20, 2014. To manage your domain, use the Admin SDK Directory and Admin SDK Reports advanced services instead. See the guide to migrating from Domain service." per the documentation page for the UserManager Class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.