Search code examples
node.jsactive-directoryldap

ldap query get all users in a group node.js


failing to find any info on the matter. I need to query an active directory server with a specified group name, and to receive back all the users it contains.

Then i can iterate through those users and use their first&last name + email + phone + accountname.

Is all that possible using Node.js? Can someone liberate me from this headache?


Solution

  • Using this link: https://www.npmjs.com/package/activedirectory#getUsersForGroup

    var groupName = 'Employees';
    
    var ad = new ActiveDirectory(config);
    ad.getUsersForGroup(groupName, function(err, users) {
      if (err) {
        console.log('ERROR: ' +JSON.stringify(err));
        return;
      }
    
      if (! users) console.log('Group: ' + groupName + ' not found.');
      else {
        console.log(JSON.stringify(users));
      }
    });