remove user from large policy group using ldaphttp://forums.asp.net/t/1751367.aspx/1?remove+user+from+large+policy+group+using+ldapWed, 21 Dec 2011 17:45:24 -050017513674740309http://forums.asp.net/p/1751367/4740309.aspx/1?remove+user+from+large+policy+group+using+ldapremove user from large policy group using ldap <p>How to effectively remove user from large policy group?<br> Now i use:<br> dirEntry = new DirectoryEntry(<br> dirEntry.Properties[&quot;msDS-PSOAppliesTo&quot;].Remove(userDn);</p> <p>problem: dirEntry only holds upto 1500 users. i have more than 1M users so i have to loop over using paging untill i find entry that holds the user, and only then call Remove(userDn). IT TAKES TO LONG, HOW DO I REMOVE THE USER POLICY MORE EFFECTIVELY?</p> <p>CURRENT UNEFFECTIVE CODE:</p> <p>DirectoryEntry dirEntry = null;<br> string LDAPQuery = LDAP_INIT &#43; &quot;CN=&quot; &#43; policy &#43; &quot;,CN=Password Settings Container,CN=System,&quot; &#43; LDAP;<br> dirEntry = new DirectoryEntry(LDAPQuery, DOMAIN &#43; &quot;\\&quot; &#43; ADS_ADMIN.userName, ADS_ADMIN.pwd);<br> dirEntry.AuthenticationType = AuthenticationTypes.Secure;<br> int ctr = 0;<br> while (ctr &lt; 1000)<br> {<br> &nbsp;if (ctr == 0)<br> &nbsp;&nbsp;dirEntry.RefreshCache(new string[] { &quot;msDS-PSOAppliesTo;range=0-1000&quot; });<br> &nbsp;else<br> &nbsp;&nbsp;dirEntry.RefreshCache(new string[] { &quot;msDS-PSOAppliesTo;range=&quot; &#43; ((ctr * 1000) &#43; 1).ToString() &#43; &quot;-&quot; &#43; ((ctr &#43; 1) * 1000).ToString() });<br> &nbsp;if (dirEntry.Properties[&quot;msDS-PSOAppliesTo&quot;].Contains(userDn))<br> &nbsp;{<br> &nbsp;&nbsp;dirEntry.Properties[&quot;msDS-PSOAppliesTo&quot;].Remove(userDn);<br> &nbsp;&nbsp;dirEntry.CommitChanges();<br> &nbsp;&nbsp;break;<br> &nbsp;}<br> &nbsp;ctr&#43;&#43;;<br> }</p> <p><span face="Consolas" size="2" style="font-family:Consolas; font-size:x-small"><span face="Consolas" size="2" style="font-family:Consolas; font-size:x-small"></span></span></p> <p>&nbsp;</p> 2011-12-20T08:16:34-05:004741073http://forums.asp.net/p/1751367/4741073.aspx/1?Re+remove+user+from+large+policy+group+using+ldapRe: remove user from large policy group using ldap <p>You can remove the group from the memberof property of the user. You will need the DistinguishedName of the group as the GroupName</p> <pre class="prettyprint">dirEntry.Properties[&quot;memberOf&quot;].Remove(GroupName);</pre> 2011-12-20T13:48:31-05:004743122http://forums.asp.net/p/1751367/4743122.aspx/1?Re+remove+user+from+large+policy+group+using+ldapRe: remove user from large policy group using ldap <p>Not working, in ldap Member-of is read-only property</p> 2011-12-21T13:29:57-05:004743622http://forums.asp.net/p/1751367/4743622.aspx/1?Re+remove+user+from+large+policy+group+using+ldapRe: remove user from large policy group using ldap <p>Seemed like that would work. Guess not. When I am adding/removing users from groups I normally use DE.Invoke(&quot;Remove&quot;, UserDistinguishedName). According to this link it will work and you should not have to loop through the members.</p> 2011-12-21T17:45:24-05:00