Google Apps Script

Class UserManager

This class allows administrators to create, update, retrieve and delete users in a Google Apps domain.

To use this class you have to first enable the Provisioning API on your domain.

 
// This example creates a new group and adds all of the domain's users to it.
 var group = GroupsManager.createGroup('testgroup', 'my new group');
 var users = UserManager.getAllUsers();
 for (var i in users) {
   group.addMember(users[i].getEmail());
 }
 

Methods

MethodReturn typeBrief description
createUser(username, givenName, familyName, password)DomainUserCreates a new user for the Google Apps domain.
createUser(username, givenName, familyName, password, passwordHashFunction)DomainUserCreates a new user for the Google Apps domain.
getAllUsers()DomainUser[]Retrieves the list of users for the Google Apps domain.
getDomain()StringRetrieves the name of the Google Apps domain being managed.
getUser(username)DomainUserRetrieves information about a single user for the Google Apps domain.
getUser(user)DomainUserRetrieves information about a single user for the Google Apps domain.

Detailed documentation

createUser(username, givenName, familyName, password)

Creates a new user for the Google Apps domain.

 
// Creates a new user "john.smith" and sets the initial password.
 var user = UserManager.createUser("john.smith", "John", "Smith", "theInitialPw");
 

Parameters

NameTypeDescription
usernameStringthe unique name that identifies the account
givenNameStringthe user's first name
familyNameStringthe user's last name
passwordStringthe password for the account

Return

DomainUser — the created user


createUser(username, givenName, familyName, password, passwordHashFunction)

Creates a new user for the Google Apps domain.

 
// Creates a new user "john.smith" and sets the initial password as an MD5 hash value.
 var user = UserManager.createUser("john.smith", "John", "Smith",
     "5f4dcc3b5aa765d61d8327deb882cf99", Utilities.DigestAlgorithm.MD5);
 

Parameters

NameTypeDescription
usernameStringthe unique name that identifies the account
givenNameStringthe user's first name
familyNameStringthe user's last name
passwordStringthe password for the account
passwordHashFunctionDigestAlgorithmthe hash format of the password parameter

Return

DomainUser — the created user

See also


getAllUsers()

Retrieves the list of users for the Google Apps domain.

 
// Logs the emails of all of the domain's users.
 var users = UserManager.getAllUsers();
 for (var i in users) {
   Logger.log(users[i].getEmail());
 }
 

Return

DomainUser[] — an array of all of the domain's users


getDomain()

Retrieves the name of the Google Apps domain being managed.

 
var domainName = UserManager.getDomain();
 

Return

String — the name of the domain being managed


getUser(username)

Retrieves information about a single user for the Google Apps domain.

 
var user = UserManager.getUser("john.smith");
 

Parameters

NameTypeDescription
usernameStringthe unique name that identifies the account

Return

DomainUser — the retrieved user account


getUser(user)

Retrieves information about a single user for the Google Apps domain.

 
// Gets the domain user object for the current user.
 var user = UserManager.getUser(Session.getUser());
 

Parameters

NameTypeDescription
userUserthe user entry identifying the account

Return

DomainUser — the retrieved user account

Deprecated methods

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.