3

次のコードがあります。

// Declare new DirectoryEntry and DirectorySearcher
DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);

// Set the properties of the DirectorySearcher
dsSearch.Filter = "(objectClass=Computer)";
dsSearch.PropertiesToLoad.Add("whenCreated");
dsSearch.PropertiesToLoad.Add("description");
dsSearch.PropertiesToLoad.Add("operatingSystem");
dsSearch.PropertiesToLoad.Add("name");

// Execute the search
SearchResultCollection computersFound = dsSearch.FindAll();

最新のコンピューター オブジェクトが一番上になるように、結果をwhenCreatedプロパティで降順に並べ替えます。

私は単純にできません:

SortOption sortedResults = new SortOption("whenCreated", SortDirection.Descending);
dsSearch.Sort = sortedResults;

サーバーがエラーを返すため (http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/183a8f2c-0cf7-4081-9110-4cf41b91dcbf/)

これを並べ替える最良の方法は何ですか?

4

2 に答える 2

1

ここでMSDNに記載されているように、サーバー側で実行できます:

      new DirectorySearcher(entry)
      {
        Sort = new SortOption("cn", SortDirection.Ascending),
        PropertiesToLoad = {"cn"}
      };

リンクされた問題のスレッドが解決されました。

AD Windows 2008 R2 でも同じ問題が発生します。

  • kb977180-v2 を適用http://support.microsoft.com/kb/977180
  • キー HKLM\System\CurrentControlSet\Services\NTDS\Parameters を追加しました
  • 文字列値「DSA Heuristics」を追加</li>
  • 値を 000000000001 に設定します
  • 再起動
  • この問題が解決した後
于 2016-10-23T11:58:31.320 に答える
0

whenCreated プロパティによって SearchResult インスタンスを比較する比較子を作成します。

public class SearchResultComparer : Comparer<SearchResult>
{
    public override int Compare(SearchResult x, SearchResult y)
    {
        //Compare two SearchResult instances by their whenCreated property
    }
}

次に、すべてのアイテムをリストにコピーします。これは、この比較子を使用してアイテムを並べ替えます。

List<SearchResult> SearchResultList = new List<SearchResult>(computersFound);
SearchResultList.Sort(new SearchResultComparer());
于 2012-04-15T00:08:20.040 に答える