Powershell: Find process that locks a file

Aus QBWiki
Zur Navigation springenZur Suche springen


Uses the <openfiles> command to find a file-locking process.

Sometimes useful when trying to delete a file.

Activate openfiles (Requires Reboot):

openfiles /local on

Working Pseudeocode example:

1 IF((Test-Path -Path $FileOrFolderPath) -eq $false) {
2     Write-Warning "File or directory does not exist."       
3 }
4 Else {
5     $LockingProcess = CMD /C "openfiles /query /fo table | find /I ""$FileOrFolderPath"""
6     Write-Host $LockingProcess
7 }