Forum Discussion

Ismaile's avatar
Ismaile
Copper Contributor
Aug 26, 2020

How to know the which user is locked the file in shared drive

Hello Team,

Can someone help me how I will get the user name who has locked the file in the shared folder?

I am getting an error like the process is being used by another process. I need a script to find out who has locked the file.

Please help me the script, I am new to PowerShell trying to figure out.

1 Reply

  • dretzer's avatar
    dretzer
    Iron Contributor

    On the fileserver with administrative permissions:

    $filename = "file.name"
    Get-SmbOpenFile | Where-Object {$_.Path -match $filename} | Format-Table -Property ClientUserName,Path -AutoSize

    For the filename you can use however much you know about the file. A partial name, full path, partial path... it will compare what you give it as filename with all open files path property and return all usernames and full pathname for the matches as a table.

    Instead of piping it to Format-Table, you could also pipe it directly to Close-SmbOpenFile to close the handle.

    Ismaile 

Resources