在apps脚本中设置changepassword =“true”

时间:2014-02-21 11:18:48

标签: javascript google-apps-script google-admin-sdk

我收集了某个OU中的所有用户。现在我想更改对象中的参数。但我收到错误代码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);
    }
}

该对象具有参数“changePasswordAtNextLogin”但我以任何方式得到错误:

[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 @ modeomain.com,kind = admin#directory#user,id = 1033d75074613787551986,isMailboxSetup = true, changePasswordAtNextLogin = false ,customerId = wC030c3310,

现在它看起来像这样,但我无法让它工作:

 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);
  }
}

它在AdminDirectory.Users.update(changePasswordAtNextLogin,x)上失败了;我正在思考resourceKey =用户变量,资源属性?   AdminDirectory.Users.update(resource,userKey)

2 个答案:

答案 0 :(得分:2)

changePasswordAtNextLogin属性不是函数。

尝试 -

x[i].changePasswordAtNextLogin = true

确保也在最后进行更新

  AdminDirectory.Users.update(resource, userKey)

答案 1 :(得分:1)

以这种方式?

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);
  }

}