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

%3CLINGO-SUB%20id%3D%22lingo-sub-1613008%22%20slang%3D%22en-US%22%3EHow%20to%20know%20the%20which%20user%20is%20locked%20the%20file%20in%20shared%20drive%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1613008%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Team%2C%3C%2FP%3E%3CP%3ECan%20someone%20help%20me%20how%20I%20will%20get%20the%20user%20name%20who%20has%20locked%20the%20file%20in%20the%20shared%20folder%3F%3C%2FP%3E%3CP%3EI%20am%20getting%20an%20error%20like%20the%20process%20is%20being%20used%20by%20another%20process.%20I%20need%20a%20script%20to%20find%20out%20who%20has%20locked%20the%20file.%3C%2FP%3E%3CP%3EPlease%20help%20me%20the%20script%2C%20I%20am%20new%20to%20PowerShell%20trying%20to%20figure%20out.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1613008%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1613176%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20know%20the%20which%20user%20is%20locked%20the%20file%20in%20shared%20drive%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1613176%22%20slang%3D%22en-US%22%3E%3CP%3EOn%20the%20fileserver%20with%20administrative%20permissions%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24filename%20%3D%20%22file.name%22%0AGet-SmbOpenFile%20%7C%20Where-Object%20%7B%24_.Path%20-match%20%24filename%7D%20%7C%20Format-Table%20-Property%20ClientUserName%2CPath%20-AutoSize%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EFor%20the%20filename%20you%20can%20use%20however%20much%20you%20know%20about%20the%20file.%20A%20partial%20name%2C%20full%20path%2C%20partial%20path...%20it%20will%20compare%20what%20you%20give%20it%20as%20filename%20with%20all%20open%20files%20path%20property%20and%20return%20all%20usernames%20and%20full%20pathname%20for%20the%20matches%20as%20a%20table.%3C%2FP%3E%3CP%3EInstead%20of%20piping%20it%20to%20Format-Table%2C%20you%20could%20also%20pipe%20it%20directly%20to%20Close-SmbOpenFile%20to%20close%20the%20handle.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F771124%22%20target%3D%22_blank%22%3E%40Ismaile%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Visitor

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

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