Question

I have collected all users in a certain OU. Now i would like to change a parameter in the objects. But i get an error code TypeError: Cannot find function changePasswordAtNextLogin in object

function admsdk() {

    var x = AdminDirectory.Users.list({
        customer: "my_customer",
        query: "orgUnitPath='/LegacyMail'", 
    });
    Logger.log(x);

    for(var i in x) {
        x[i].changePasswordAtNextLogin(true);
    }
}

The object have the parameter "changePasswordAtNextLogin" but i get errors any way:

[14-02-21 12:13:41:182 CET] {users=[{etag="7XeU3X9xgwyeKXCCsYZGUBcBlgw/8gkNyn34hZeT3Dwd78gpIG0OyMEo", orgUnitPath=/LegacyMail, emails=[{address=abbec@mydomain.com, primary=true}, suspended=false, primaryEmail=abbec@mydomain.com, kind=admin#directory#user, id=1033d75074613787551986, isMailboxSetup=true, changePasswordAtNextLogin=false, customerId=wC030c3310,

Now it look's like this, but i can't get it to work:

 function admsdk() {

  var x = AdminDirectory.Users.list({
    customer: "my_customer",
    query: "orgUnitPath='/LegacyMail'", 
  });
  Logger.log(x);

  for(var i in x){
   x[i].changePasswordAtNextLogin = true;
      AdminDirectory.Users.update(changePasswordAtNextLogin, x);
  }
}

It fail's on the AdminDirectory.Users.update(changePasswordAtNextLogin, x); am i thinking right resourceKey = the user variable, and the resource the property ? AdminDirectory.Users.update(resource, userKey)

Was it helpful?

Solution 2

and in that way?

function admsdk() {

  var userlist = AdminDirectory.Users.list({
                 customer: "my_customer",
                 query: "orgUnitPath='/LegacyMail'", 
                 });

  var users=userList.users;

  for (var i = 0; i < users.length; i++) {
      users[i].changePasswordAtNextLogin = true;
      AdminDirectory.Users.update(users[i], users[i].primaryEmail);
  }

}

OTHER TIPS

changePasswordAtNextLogin is a property not a function.

Try -

x[i].changePasswordAtNextLogin = true

Make sure to also do an update at the end

  AdminDirectory.Users.update(resource, userKey)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top