title: Compare directory with sub-folders
body: <p>I have been have a tough time with this but I am trying to do a compare between two servers and have them compare all of the files from one server to the other. Even inside the subfolders. So far I've gotten it to compare the folder names and files but can't get it to go inside the folders and compare the contents. Here's a few things I've tried. </p>
  
  <pre><code>$A = Get-ChildItem -Recurse -path $Path
  $B = Get-ChildItem -Recurse -path $PAth1
  Compare-Object -ReferenceObject $A -DifferenceObject $B -PassThru
  </code></pre>
  
  <p>This is what I started with and it works the best but still doesn't go inside the sub-folders. I also tried to use foreach statements with Arrays to store the content in an array and compare the arrays but this doesn't seem to be working at all. </p>
  
  <pre><code>$FileDirectoryA = "Path"
  $FileDirectoryC = "path"
  $A = foreach($folderA in Get-ChildItem $fileDirectoryA)
  {
      $FolderA
  }
  $B = foreach($FileA in Get-ChildItem $ArrayA)
  {
      $FileA
  }
  $C = foreach($folderC in Get-ChildItem $fileDirectoryC)
  {
      $FolderC
  }
  $D = foreach($FileC in Get-ChildItem $ArrayC)
  {
      $FileC
  }
  
  Compare-Object $B $D
  </code></pre>
  
  <p>When I try and just do a </p>
  
  <pre><code>Compare-Object $Path $Path2 
  </code></pre>
  
  <p>It errors on all of the folders saying permission denied which doesn't make much sense to me.</p>
  
  <p>Thanks,
  Andrew</p>