Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a way to use the windows power shell to trace what application has a resource lock on a file?

Here is what i am looking for:

  • A command line or script to show the application that has a lock on a file.
  • A bonus to the above wold be detection of the user account that has the lock and how long the lock has persisted.

Follow up:

  • There is a power tool by SysInternals that will allow you to capture a full dump in the command shell of the above.
  • I found a script that appears to do the job as well (replace with the full path and file you want to see):

    PS> $handle = handle

    PS> foreach ($line in $handle) { if ($line -match '\S+\spid:') { $exe = $line } elseif ($line -match '') { "$exe - $line" } }

share|improve this question
up vote 1 down vote accepted

Handle from Windows Sysinternals is a command line utility that can be used to determine what handles have a lock on a file. You can run handle from the command line with

handle c:\fileToCheck

Or you could write a PowerShell script to wrap the functionality of handle.

share|improve this answer
I just found the same thing and updated the post with the script. Thanks. – Random Developer Jul 20 '09 at 13:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.