Handle is a PowerShell wrapper for Handle.exe, a Sysinternals tool for finding and closing locked files.
- Install-SysInternals
- Get-LockedFiles
- Close-LockedFiles
Installing the SysInternals tools can be done with the cmdlet Install-SysInternals. This uses Chocolatey to handle the install, so you will need to have Chocolatey installed on your machine or it won't work
Install-SysInternals
Finding locked files can be done with the cmdlet Get-LockedFiles
Get-LockedFiles -Path 'C:\TestPath'
To close these locked files, you can either pipe the results of the previous command into Close-LockedFiles, or just provide it any path
Get-LockedFiles -Path 'C:\TestPath' | Close-LockedFiles
OR
Close-LockedFiles -Path 'C:\TestPath'