0
這給我們的ActiveDirectory UserPrincipals的列表,用戶在組「X」:過濾器用戶可以通過屬性
var domainContext = new PrincipalContext(ContextType.Domain);
var groupPrincipal = GroupPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, "x");
現在我將如何通過自定義屬性篩選該列表中的用戶?所有用戶都在自定義屬性「Building」中有條目,並且我希望列表僅包含來自某個建築物的用戶。
SOLUTION
愚蠢的我...投的成員groupPrincipal到的DirectoryEntry,然後訪問屬性..
foreach (var member in groupPrincipal.Members)
{
// maybe some try-catch ..
System.DirectoryServices.DirectoryEntry i = (System.DirectoryServices.DirectoryEntry)member.GetUnderlyingObject();
if (i.Properties["building"].Value.toString() == "NSA HQ")
{
// Do stuff here
}
}
http://stackoverflow.com/questions/7151770/retrieve-ad-custom-attribute-in-one-batch可能會有所幫助。 – mswietlicki
謝謝,我編輯了我的問題。作爲回答發佈,我會投票。 – peter