title: How to copy file for one time a day - elegant solution
body: <p>I have remote server, where will be uploaded one file per day. I don't know when the file will be uploaded. I need to COPY this file to another server for processing and I need to do this just once per file (once a day). When the file is uploaded on remote server, I need to copy it within a hour, so I have to run this script at least once per hour. I'm using this script:</p>
  
  <pre><code># Get yesterday date
  $date = (Get-Date).Adddays(-1) | Get-Date -Format yyyyMMdd
  $check = ""
  $check = Get-Content c:\checkiftransfered.txt
  
  # Test if file checkiftransfered.txt contains True or False. If it contains True, file for this day was already copyied
  if ($check -ne "True") {
      #Test if file exists - it has specific name and yesterday date
      if(Test-Path \\remoteserver\folder\abc_$date.xls) {
  
          Copy-Item \\remoteserver\folder\abc_$date.xls \\remoteserver2\folder\abc_$date.xls
          # Write down information that file was already copyied
          $check = "True" | Out-File c:\checkiftransfered.txt
  
      } else { Write-Host "File has not been uploaded."}
  } else { Write-Host "File has been copyied."}
  # + I will need another script that will delete the checkiftransfered.txt at 0:00
  </code></pre>
  
  <p>It will work fine, I think, but I'm looking for more elegant solution - the best way how to solve it. Thank you</p>