Delete file that locked by Windows Process

Steps to delete file that locked by Windows Process

  1. Open Task Manager – Performance – Open Resource Manager


  1. Go to CPU – Associated Handles and search for the file which locked by Windows Process


Right click on the process which locked the file to end / kill it, and you should be able to delete the file in Windows Explore now

The PowerShell way

  1. Download Get-FileLockProcess.ps1

  2. Import the downloaded Function, End the process and delete the file

#Import Function
. C:\MyPowerShell\Get-FileLockProcess.ps1

$File = "C:\Temp\SendEmail.csv"
$Process = Get-FileLockProcess -FilePath $File

#Kill the process
Stop-Process -Id $ 

#Wait for 5 seconds 
Start-Sleep 5

#Delete the file
Remove-Item $File -Force 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top