{"id":658,"date":"2011-12-08T11:06:33","date_gmt":"2011-12-08T09:06:33","guid":{"rendered":"http:\/\/hen.co.za\/blog\/?p=658"},"modified":"2011-12-08T11:06:33","modified_gmt":"2011-12-08T09:06:33","slug":"directorysearcher-and-sizelimit","status":"publish","type":"post","link":"https:\/\/hen.co.za\/blog\/2011\/12\/directorysearcher-and-sizelimit\/","title":{"rendered":"DirectorySearcher and SizeLimit"},"content":{"rendered":"<p>Seems like each time you actually wants to use some MS technology for real you find a serious bug in it&#8230;<\/p>\n<p>If you query active directory to get a list of say, all the machines on the network and the list happens to be bigger than a 1000 items there is a problem using DirectorySearcher. There is a property called SizeLimit but even if you set it to anything larger than a 1000 it always only return a 1000 items.<\/p>\n<p>Fortunately (like a lot of other cases) there is a way around it. DirectorySearcher have another property for PageSize which if you set that then the size limit is ignored and you can access more than the 1000 items.<\/p>\n<p>e.g.<\/p>\n<p><span style=\"color: #0000ff;\">string<\/span> filter = &#8220;(objectCategory=Computer)&#8221;;<br \/>\n<span style=\"color: #0000ff;\">using<\/span> (<span style=\"color: #0000ff;\">DirectorySearcher<\/span> searcher = <span style=\"color: #0000ff;\">new DirectorySearcher<\/span>(filter))<br \/>\n{<br \/>\n\/\/searcher.SizeLimit = 2000; \/\/ignored<br \/>\nsearcher.PageSize = 1000;<br \/>\n<span style=\"color: #0000ff;\">SearchResultCollection<\/span> matches = searcher.FindAll();<br \/>\n<span style=\"color: #0000ff;\">foreach<\/span> (<span style=\"color: #0000ff;\">SearchResult<\/span> match in matches)<br \/>\n{<br \/>\n<span style=\"color: #0000ff;\">DirectoryEntry<\/span> de = match.GetDirectoryEntry();<br \/>\n&#8230;<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seems like each time you actually wants to use some MS technology for real you find a serious bug in it&#8230; If you query active directory to get a list of say, all the machines on the network and the &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/hen.co.za\/blog\/2011\/12\/directorysearcher-and-sizelimit\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7,104,8,9,303],"class_list":["post-658","post","type-post","status-publish","format-standard","hentry","category-development","tag-net","tag-bug","tag-c","tag-code","tag-development"],"_links":{"self":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/comments?post=658"}],"version-history":[{"count":1,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/658\/revisions"}],"predecessor-version":[{"id":659,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/posts\/658\/revisions\/659"}],"wp:attachment":[{"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/media?parent=658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/categories?post=658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hen.co.za\/blog\/wp-json\/wp\/v2\/tags?post=658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}