Find processes that have open handles to your files - Powershell

Note: Cross posted from Sajay.

Permalink

This seemed like a really nice mix of handle.exe from sysinternals and powershell.

Check out the script at https://msgoodies.blogspot.com/2009/03/get-openfile.html

Update fix for get-process piping

**

You have to remove the '.exe' from the output from handle.exe to get it working to pipe it to gps.

param($fileFilter=$(throw "Filter must be specified"))
c:\sysint\handle.exe $fileFilter | foreach {
if ($_ -match '^(?<program>\S*)\s*pid: (?<pid>\d*)\s*(?<handle>[\da-z]*):\s*(?<file>(\\\\)|([a-z]:).*)') {
$matches | select @{n="Path";e={$_.file}},@{n="Handle";e={$_.handle}},@{n="Pid";e={$_.pid}},@{n="ProcessName";e={$_.Program.Replace(".exe","") }}
}
}