title: How to ensure the latest two files are copied with matching dates using powershell?
body: <p>I am using Powershell to copy two files into a drive. These files are created everyday, however sometimes one file is updated and the other does not. How do I ensure that the latest files are copied and the dates match. i.e if File A is as of 26.6.19 and File B is as of 26.6.19 copy these two. However, if File A is as of 26.6.19 but File b is as of 25.6.19 then I will be required to use File A as of 25.6.19 and vice versa. </p>
  
  <p>I have tried using the creation date but this is where my problem is since the dates could be different</p>
  
  <p>$bak_path = "File Path"
  get-childitem -path $bak_path -Filter "File A*.csv_AABBCC" | </p>
  
  <pre><code>where-object { -not $_.PSIsContainer } | 
  
    Sort-Object $_.CreationTime |
  
  select-object -last 1 | 
  
  
  copy-item -Destination File Location
  </code></pre>
  
  <p>get-childitem -path $bak_path -Filter "File B*.csv_AABBCC" | </p>
  
  <pre><code>where-object { -not $_.PSIsContainer } | 
  
    Sort-Object $_.CreationTime |
  
  select-object -last 1 |    
  
  copy-item -Destination File Location
  </code></pre>