Command line to close open files in share - (ET)

I am trying to write a script that will close all open file inside a certain share folder. Anyone know if this can be accomplished via command line?

Something that would accomplish the same as manually going to Computer Management, looking for a certain folder, then right clicking all the files and choosing 'close open file.'
LVL 2
tabushAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoninCommented:
Yes, through Powershell, as usual.
Close-SmbOpenFile
0
tabushAuthor Commented:
Thanks.
Then i just put the file path at the end?
0
RoninCommented:
Scroll down to the examples section
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Shaun VermaakTechnical Specialist IVCommented:
From that link
Get-SmbOpenFile | Where-Object -Property ShareRelativePath -Match ".DOCX" | Close-SmbOpenFile -Force

Open in new window

0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
It is more of
Get-SmbOpenFile |? { $_.Path -like 'C:\Share1\Folder1\*' } | Close-SmbOpenFile -Force

Open in new window

as we want to close all files open in a specific path.
Note that we cannot see the share name used, we need to filter for the absolute path hence.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tabushAuthor Commented:
Thank you. I will try this out.
Sorry i didnt notice your original answer had that link.
0
tabushAuthor Commented:
@Qlemo - that doesnt seem to work
@Shaun - Not sure how i plug in the path. I tried replacing ShareRelativePath with the local path and removing -match because i want all files but it didnt work.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
If my suggestion does not work, you need to look at the path literal used in -like. This needs to be the full path to the folder you want to check, plus an trailing asterisk to match everything following the path name (subfolders and files).

ShareRelativePath is not suitable, as it contains only the part starting from the share location, without any information about the share itself.
0
tabushAuthor Commented:
So i tried this command to see if it will even report the open files and its not
Get-SmbOpenFile | Where-Object Path -eq "D:\FTP Share\TEST DROP FOLDER\" | Format-List

Open in new window


I am seeing them in computer manager (see screenshot)
computer manager
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Path contains the complete path, including the file name. So with your code you should get all open connections for the folder only - and that works for me on my test machine.
You should use the like as I have shown, to catch all files and folders opened below that path, and not just the folder itself.

What do you get if you do not apply any filter?
0
tabushAuthor Commented:
thank you. I ended up finding an alternate solution to what we were trying to solve.
In this scenario we can just delete the files so that was easier to accomplish via script.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The comment in #a42440374 is approved and works, if used correctly. It is simple enough to be used correctly.

The suggested author comment is not acceptable (does not contain the necessary details to consider it as such).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2012

From novice to tech pro — start learning today.