簡體   English   中英

擴展用戶原理極慢

[英]Extended UserPrinciple Extremely Slow

我正在開發一個程序,該程序需要循環超過30k AD用戶。 對於最初的化身,我使用了System.Management.Automation.PowerShell。 這很完美,但是我不喜歡從C#全部內部執行PowerShell的味道。

然后,我改用DirectoryServices.AccountManagement作為更“純”的解決方案。 我需要獲取用戶的標題和管理員。 因此,我不得不擴展UserPrinciple。 但是,執行此操作后,我發現獲得標題或經理需要很長時間。 對於我的環境,檢索這2個屬性大約需要160毫秒。

當我嘗試訪問“標題”或“管理器”屬性時,似乎出現了延遲。

例子:

原始代碼-每個循環迭代所用的時間少於2ms:

ps.AddCommand("Get-Aduser");
ps.AddParameter("Filter", "*");
ps.AddParameter("SearchBase", dName);
string[] props = { "Name", "EmailAddress", "GivenName", "Surname", "Title", "Manager", "Enabled", "EmployeeID" };
ps.AddParameter("Properties", props);

foreach (PSObject i in ps.Invoke())
{
    Console.WriteLine(i.Properties["Title"].Value.ToString());
}

新代碼-每個循環迭代大約需要165ms:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "*******", distinguishedName);

UserPrincipalsEx qbeUser = new UserPrincipalsEx(ctx);
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
PrincipalSearchResult<Principal> res = srch.FindAll();
foreach (UserPrincipalsEx i in res)
{
    Console.WriteLine(i.Title);
}

我在這里缺少什么嗎?還是只需要花費一些時間單獨查詢擴展屬性?

對我而言,明顯的不同是在Powershell示例中,您在執行命令之前指定了所需的屬性。

在C#版本中,您在搜索廣告后正在查詢.title屬性。 由於未加載該屬性,因此可能會再次從AD獲取記錄

您是否有可能告訴PrincipalSearcher對象要在結果中包括哪些字段?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM