• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 102
  • Last Modified:

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.'
0
tabush
Asked:
tabush
  • 5
  • 4
  • 2
  • +1
1 Solution
 
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
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

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

Open in new window

0
 
QlemoBatchelor, 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
 
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
 
QlemoBatchelor, 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
 
QlemoBatchelor, 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
 
QlemoBatchelor, 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now