title: PowerShell File Watcher Register-ObjectEvent - Wait For File To Complete Copying
body: <p>The below code is checking for new files in a specified directory <code>$folderCompleted</code>.</p>
  
  <p>Currently, when a small file is placed into that directory (~1MB) the Move-Item command and other file reading checks complete successfully. </p>
  
  <p>However when a large file is moved into this directory, the Object event is called before the file is completely moved (copied over) into that directory. This causing the file checks and the Move-Item command to fail since the file is still in use.</p>
  
  <pre><code># File Watcher
  $filter = '*.*'
  $fsw = New-Object IO.FileSystemWatcher $folderCompleted, $filter -Property @{
      IncludeSubdirectories = $true
      NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
  }
  
  $onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
      $path = $Event.SourceEventArgs.FullPath
      $name = $Event.SourceEventArgs.Name
      $changeType = $Event.SourceEventArgs.ChangeType
      $timeStamp = $Event.TimeGenerated
      Write-Host "The file '$name' was $changeType at $timeStamp"
  
      # File Checks
  
      # Move File
      Move-Item $path -Destination $destinationPath -Verbose
  }
  </code></pre>
  
  <p>How can I place a check to see if the file is not still being copied over?</p>