title: Force Remove a Folder in-use using Powershell
body: <p>I've created a script which at the end deletes all the associated files, self-destructs by deleting itself, and then it's supposed to delete the folder it is contained in as well.</p>
  
  <p>I've tried several ways of closing Windows Explorer, searching through active processes and killing any related processes, but still cannot successfully delete the folder despite being able to self-destruct the script itself.</p>
  
  <pre><code>Set-Location -Path $PSScriptRoot
  
  Remove-Item -Path $PSScriptRoot\Mobile -Force -Recurse
  
  Remove-Item -Path $PSScriptRoot\NoMobile -Force -Recurse
  
  Remove-Item -Path $MyInvocation.MyCommand.Source -Force -Recurse
  
  Set-Location ..
  
  Remove-Item $foldername -Force -Recurse
  </code></pre>
  
  <p>The last line throws an error that "The process cannot access the file...because it is being used by another process".</p>
  
  <p>Any thoughts?</p>