Aug 26 2020 02:07 AM
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.
Aug 26 2020 03:43 AM
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.