title: How to keep 2 folders in sync using powershell script
body: <p>We have two folders:</p>
  
  <ul>
  <li><code>FolderA</code>: D:\Powershell\Original</li>
  <li><code>FolderB</code>: D:\Powershell\copy</li>
  </ul>
  
  <p>Now, I want to keep <code>FolderA</code> and <code>FolderB</code> in sync (i.e. when a user changes/adds/removes a file/directory in <code>FolderA</code> then same changes should happen in <code>FolderB</code>).</p>
  
  <p>I tried :</p>
  
  <pre class="lang-powershell prettyprint-override"><code>$Date = Get-Date 
  $Date2Str = $Date.ToString("yyyMMdd") 
  $Files = gci "D:\Powershell\Original" 
  ForEach ($File in $Files){
          $FileDate = $File.LastWriteTime
          $CTDate2Str = $FileDate.ToString("yyyyMMdd")
          if ($CTDate2Str -eq $Date2Str) { 
             copy-item "D:\Powershell\Original" "D:\Powershell\copy" -recurse    
             -ErrorVariable capturedErrors -ErrorAction SilentlyContinue; 
          } 
  }
  </code></pre>
  
  <p>But this would require a similar powershell script for deletion of files in <code>FolderA</code> and changes in <code>FolderB</code>.</p>