c# - Filter users by attribute -


this gives list of userprincipals our activedirectory users in group "x":

var domaincontext = new principalcontext(contexttype.domain); var groupprincipal = groupprincipal.findbyidentity(domaincontext, identitytype.samaccountname, "x"); 

now how filter users in list custom attribute? users have entry in custom property "building", , want list contain users building.

solution

stupid me ... cast members groupprincipal directoryentry, access properties ..

        foreach (var member in groupprincipal.members)         {             // maybe try-catch ..             system.directoryservices.directoryentry = (system.directoryservices.directoryentry)member.getunderlyingobject();             if (i.properties["building"].value.tostring() == "nsa hq")             {                 // stuff here             }          } 

yes, may use member.getunderlyingobject()

var members = groupprincipal.members.where(member=>(member.getunderlyingobject() directoryentry).properties["building"].value.tostring() == "nsa hq"); 

as pointed out in retrieve ad custom attribute in 1 batch


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -