title: Powershell Foreach Loop Is Using My Files
body: <p>I have the following code</p>
  <pre><code>$top = Get-ChildItem -File C:\SomeFolder\1\ -Recurse -filter *.evtx
  foreach ($file in $top) {
      $get = (Get-WinEvent -Path C:\SomeFolder\1\$file  -erroraction 'silentlycontinue').count
      if ($get -eq '0') {
          Remove-Item -Path  C:\SomeFolder\1\$file -Recurse -Force
      }
  }
  </code></pre>
  <p>The problem is that the files that I'm trying to delete are in use by the loop.<br />
  The following error appears - &quot;Remove-Item : Cannot remove item The process cannot access the file because it is being used by another process.&quot;<br />
  I even tried exiting with break but it didn't help.
  Any suggestions?</p>
  <p>Thanks!</p>