Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The primary group of a user is given by <code>primaryGroupID</code> attribute of a user. In fact <code>primaryGroupID</code> contains the RID of the primary group in a string format. That's why, I first get the SID of the group you are looking for users, then I compute (badly) the RID, and I search for users with a <code>primaryGroupID</code> containing the RID.</p> <pre><code>/* Connection to Active Directory */ DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr"); /* Directory Search for agroup */ string givenGrpName = "MonGrpSec"; DirectorySearcher dsLookFor = new DirectorySearcher(deBase); dsLookFor.Filter = string.Format ("(sAMAccountName={0})", givenGrpName); dsLookFor.SearchScope = SearchScope.Subtree; dsLookFor.PropertiesToLoad.Add("cn"); dsLookFor.PropertiesToLoad.Add("objectSid"); SearchResult srcGrp = dsLookFor.FindOne(); /* Get the SID */ SecurityIdentifier secId = new SecurityIdentifier(srcGrp.Properties["objectSid"][0] as byte[], 0); /* Find The RID (sure exists a best method) */ Regex regRID = new Regex(@"^S.*-(\d+)$"); Match matchRID = regRID.Match(secId.Value); string sRID = matchRID.Groups[1].Value; /* Directory Search for users that has a particular primary group */ DirectorySearcher dsLookForUsers = new DirectorySearcher(deBase); dsLookForUsers.Filter = string.Format("(primaryGroupID={0})", sRID); dsLookForUsers.SearchScope = SearchScope.Subtree; dsLookForUsers.PropertiesToLoad.Add("cn"); SearchResultCollection srcUsers = dsLookForUsers.FindAll(); foreach (SearchResult user in srcUsers) { Console.WriteLine("{0} is the primary group of {1}", givenGrpName, user.Properties["cn"][0]); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload