title: Force close files that are in use when the script runs
body: <p>I have following script that take files older than specified day and saves them as archive in a different folder. The script works fine with most of the files but for some files it gives this error and doesn’t include those file in the archive.</p>
  
  <pre><code>Move-Item : The process cannot access the file because it is being used by another process.
  At C:\SRS\SRSLogArchieveScript.ps1:49 char:13
  +             Move-Item &lt;&lt;&lt;&lt;  $item.FullName $destPathController -force;
      + CategoryInfo          : WriteError: (C:\SRS\Controll...apter0611-1.log:FileInfo) [Move-Item], IOException
      + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
  </code></pre>
  
  <p>However I am using <code>-force</code> with <code>-move item</code> but it still have this issue. Is there a way I can actually force close all the files in use to make sure all files are included as a part of archive.</p>
  
  <pre><code>try
  {
  foreach( $item in (Get-ChildItem $sourcePath -recurse | Where-Object { $_.CreationTime -le $archiveTillDate }) )
  {
  $item.FullName;
  Move-Item $item.FullName $destPath -force;
  }
  }
  catch
  {
  $_.Exception.Message;
  }
  Finally
  {
  #Executing Zip Command to Archieve:
  &amp; $pathTo7ZipExe $arguments;
  
  #Delete temporary log archieve directory
  Remove-Item $logArchieve -recurse;
  
  }
  </code></pre>