by Administrator
24. May 2010 23:26
You need to be careful if you are adding members to large groups (i.e. over 1500 members). The standard approach in the first code sample doesn't work as the DE.Properties["member"] property will only return 1500 members - and you can't add any more to this
The solution is shown in the 2nd code snippet using the ADSI Edit Invoke statement
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using ActiveDs;
namespace DirectoryServices
{
static class ADGroup
{
const string GROUP_PATH = "LDAP://PATHTOGROUPGOESHERE";
const string MEMBER_PATH = "LDAP://PATHTOUSERGOESHERE";
const string MEMBER_DISTINGUISHED_NAME = "USERDISTINGUISHEDNAMEGOESHERE";
public static void AddMember()
{
using (DirectoryEntry DE = new DirectoryEntry(GROUP_PATH))
{
DE.Properties["member"].Add(MEMBER_DISTINGUISHED_NAME);
DE.CommitChanges();
}
}
}
}
Use the code below to add members to large groups
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using ActiveDs;
namespace DirectoryServices
{
static class ADGroup
{
const string GROUP_PATH = "LDAP://PATHTOGROUPGOESHERE";
const string MEMBER_PATH = "LDAP://PATHTOUSERGOESHERE";
const string MEMBER_DISTINGUISHED_NAME = "USERDISTINGUISHEDNAMEGOESHERE";
public static void AddMember ()
{
using (DirectoryEntry DE = new DirectoryEntry(GROUP_PATH))
{
DE.Invoke("Add", new Object[] { MEMBER_PATH });
}
}
}
}