title: Comparing a directory's parent against another directory in a where pipe
body: <p>Imagine I have a directory structure like so:</p>
  
  <pre><code>parentDir\dirA\foo\
  parentDir\dirB\foo\
  parentDir\dirC\
  parentDir\dirD\bar\foo\
  parentDir\dirE\foo\
  parentDir\dirF\
  </code></pre>
  
  <p>I want to select only the directories that a) are immediate children of parentDir, and b) have a foo directory as an immediate child.</p>
  
  <p>So dirs A, B, and E qualify, whilst C, D, and F don't.</p>
  
  <p>I first tried this powershell script:</p>
  
  <pre><code>$rootDir = gi(".")
  dir -include "*foo*" -recurse | ? {$_.PSIsContainer -eq $true} | % {$_.Parent} 
      | ? { $_.Parent -eq $rootDir } 
  </code></pre>
  
  <p>It finds all foo items below the root dir, filters out non-directories, goes up one to the intermediate directories, then filters out any directory which is not a child of the root dir.</p>
  
  <p>This returns an empty list.</p>
  
  <p>However if I change the last where clause as follows:</p>
  
  <pre><code>? { $_.Parent.FullName -eq $rootDir.Fullname }
  </code></pre>
  
  <p>It works, and I get the correct directories output.</p>
  
  <p>So my question is, why won't a direct compare between directory objects work?  It may seem like a little thing but it implies there's some hole in my understanding of powershell objects.</p>
  
  <p>(Also, feel free to critique my powershell coding style in the scripts, or point out quicker/more correct ways of doing this)</p>