title: Best way to do a remote directory compare with Powershell
body: <p>I have 2 folders:</p>
  
  <pre><code>$srcPath = \\stagingserver
  $destPath = \\productionserver
  </code></pre>
  
  <p>I'd like to compare the two to determine what changes are in the $src folder than haven't been pushed to production yet. The project is ~4000 files over 100 directories totalling ~80mb. I'm currently doing a hash compare like so:</p>
  
  <pre><code>$src = Get-ChildItem $srcPath -Recurse
  $dest = Get-ChildItem $destPath -Recurse 
  $same = Compare-Object $src $dest -Property Name, Length, LastWriteTime -passthru -includeequal -excludeDifferent
  
  $srcTree = Get-ChildItem $src -Recurse -exclude $same | Where-Object {!$_.psiscontainer } | get-hash
  $destTree = Get-ChildItem $dest -Recurse -exclude $same | Where-Object {!$_.psiscontainer } | get-hash  
  
  $diff = Compare-Object -ReferenceObject $srcTree -differenceObject $destTree | ? {$_.SideIndicator -eq "&lt;=" } | % {$_.InputObject.Path}
  </code></pre>
  
  <p>It takes ~5 minutes to do. I take it because it needs to copy everything locally to perform the hash. How can I do this quicker? Is there a way to maintain a hash value for every file on the server? Should I execute scripts remotely?</p>