Is there a Powershell command to check if a file is in use by another user? If not, what would it take to write a script that can?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can never tell if a file is currently being used only that it was recently being used. The reason why is that the moment the script returns the file could be closed by whatever program was previously using it. Writing scripts like this will only lead to flaky behavior.
A much better approach is to just do whatever the script was going to do if the file wasn’t in use and catch the exceptions that result from a use conflict. The end result will be a much simpler and more reliable program.