
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Searching Active Directory with PowerShell</title>
	<atom:link href="http://www.leadfollowmove.com/archives/powershell/searching-active-directory-with-powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leadfollowmove.com/archives/powershell/searching-active-directory-with-powershell</link>
	<description>Adam Bell on Deployment, Automation, PowerShell et al</description>
	<lastBuildDate>Thu, 25 Feb 2010 23:14:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: AdamBell</title>
		<link>http://www.leadfollowmove.com/archives/powershell/searching-active-directory-with-powershell/comment-page-1#comment-22</link>
		<dc:creator>AdamBell</dc:creator>
		<pubDate>Tue, 20 Feb 2007 09:50:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=49#comment-22</guid>
		<description>HI Chris,

Thanks for the thoughtful comment.

I am aware of page sizing when retrieving result from AD. This isn&#039;t the cause of problems with the second example as I am using a very small test domain in VMware to sandbox my testing from live. I&#039;m glad you raised the point though. I had been deliberatly keeping my examples simple.

I have read a couple of developers rating the book you mention highly. I should really add it to my Amazon Wishlist.

While we&#039;re on the topic of books, if anyone is interested in good AD books then the two I highly recemend are:

Active Directory Forestry
by John Craddock and Sally Storey
# ISBN-10: 0954421809
# ISBN-13: 978-0954421809

Active Directory Cookbook for Windows Server 2003 and Windows 2000
By Robie Allen
# ISBN-10: 0596004648
# ISBN-13: 978-0596004644

They are no related to PowerShell, howerver the AD content of both is excellent!

Cheers

Adam</description>
		<content:encoded><![CDATA[<p>HI Chris,</p>
<p>Thanks for the thoughtful comment.</p>
<p>I am aware of page sizing when retrieving result from AD. This isn&#8217;t the cause of problems with the second example as I am using a very small test domain in VMware to sandbox my testing from live. I&#8217;m glad you raised the point though. I had been deliberatly keeping my examples simple.</p>
<p>I have read a couple of developers rating the book you mention highly. I should really add it to my Amazon Wishlist.</p>
<p>While we&#8217;re on the topic of books, if anyone is interested in good AD books then the two I highly recemend are:</p>
<p>Active Directory Forestry<br />
by John Craddock and Sally Storey<br />
# ISBN-10: 0954421809<br />
# ISBN-13: 978-0954421809</p>
<p>Active Directory Cookbook for Windows Server 2003 and Windows 2000<br />
By Robie Allen<br />
# ISBN-10: 0596004648<br />
# ISBN-13: 978-0596004644</p>
<p>They are no related to PowerShell, howerver the AD content of both is excellent!</p>
<p>Cheers</p>
<p>Adam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Warwick</title>
		<link>http://www.leadfollowmove.com/archives/powershell/searching-active-directory-with-powershell/comment-page-1#comment-21</link>
		<dc:creator>Chris Warwick</dc:creator>
		<pubDate>Mon, 19 Feb 2007 21:20:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.leadfollowmove.com/?p=49#comment-21</guid>
		<description>Hi Adam,

Thanks for the posts!  I have a couple of comments on the Directory Searcher samples you show in this post: 

Your first sample is the correct way to search.  It&#039;s ALWAYS more efficient to filter in the provider (whether you&#039;re using directorySearcher() or get-childitem - whatever).  When you do a findAll in the second sample you may be trying to retrieve 1000&#039;s of objects in any reasonably sized directory.

Secondly, this is probably the reason your second sample gives inconsistent results.  The search will only return a fixed amount of information in one chunk - even if more items match your query.  If the entry you need happens to be in the chunk returned then your code will work.  If it&#039;s not then the code will fail.   The way around this is to do a paged query (set the pagezise attribute to &quot;1000&quot; - the actual value is fairly irrelevent, but 1000 is the value used by convention). This will ensure you get ALL the results back (could be SLOW!).  Alternatively - and preferably - you can get around this by filtering in the provider as in the first sample. [I&#039;ve just read your Search Tips and you allude to this there:-)]

Thirdly (a small point) - findone() under the covers actually does a findall() and returns the first result.  I find this misleading so I always explicitly use findall() because it&#039;s clear what&#039;s going on.  You might think findone() is quicker, but actually it&#039;s not!

Finally, you&#039;re right - it&#039;s more functional to return a directoryEntry rather than a searchresult - but retrieving the directoryEntry always results in ANOTHER LDAP query - so if efficiency is important you should only call GetDirectoryEntry() when you really need too.

HTH!

Chris

PS.  I only know this stuff because I read &quot;The .NET Developer&#039;s Guide to Directory Services Programming&quot; by Kaplan &amp; Dunn.  An excellent book which I recommend to people whenver I get the chance!</description>
		<content:encoded><![CDATA[<p>Hi Adam,</p>
<p>Thanks for the posts!  I have a couple of comments on the Directory Searcher samples you show in this post: </p>
<p>Your first sample is the correct way to search.  It&#8217;s ALWAYS more efficient to filter in the provider (whether you&#8217;re using directorySearcher() or get-childitem &#8211; whatever).  When you do a findAll in the second sample you may be trying to retrieve 1000&#8242;s of objects in any reasonably sized directory.</p>
<p>Secondly, this is probably the reason your second sample gives inconsistent results.  The search will only return a fixed amount of information in one chunk &#8211; even if more items match your query.  If the entry you need happens to be in the chunk returned then your code will work.  If it&#8217;s not then the code will fail.   The way around this is to do a paged query (set the pagezise attribute to &#8220;1000&#8243; &#8211; the actual value is fairly irrelevent, but 1000 is the value used by convention). This will ensure you get ALL the results back (could be SLOW!).  Alternatively &#8211; and preferably &#8211; you can get around this by filtering in the provider as in the first sample. [I've just read your Search Tips and you allude to this there:-)]</p>
<p>Thirdly (a small point) &#8211; findone() under the covers actually does a findall() and returns the first result.  I find this misleading so I always explicitly use findall() because it&#8217;s clear what&#8217;s going on.  You might think findone() is quicker, but actually it&#8217;s not!</p>
<p>Finally, you&#8217;re right &#8211; it&#8217;s more functional to return a directoryEntry rather than a searchresult &#8211; but retrieving the directoryEntry always results in ANOTHER LDAP query &#8211; so if efficiency is important you should only call GetDirectoryEntry() when you really need too.</p>
<p>HTH!</p>
<p>Chris</p>
<p>PS.  I only know this stuff because I read &#8220;The .NET Developer&#8217;s Guide to Directory Services Programming&#8221; by Kaplan &amp; Dunn.  An excellent book which I recommend to people whenver I get the chance!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
