tabush
asked on
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.'
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.'
ASKER
Thanks.
Then i just put the file path at the end?
Then i just put the file path at the end?
Scroll down to the examples section
From that link
Get-SmbOpenFile | Where-Object -Property ShareRelativePath -Match ".DOCX" | Close-SmbOpenFile -Force
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. I will try this out.
Sorry i didnt notice your original answer had that link.
Sorry i didnt notice your original answer had that link.
ASKER
@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.
@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.
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.
ShareRelativePath is not suitable, as it contains only the part starting from the share location, without any information about the share itself.
ASKER
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?
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?
ASKER
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.
In this scenario we can just delete the files so that was easier to accomplish via script.
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).
The suggested author comment is not acceptable (does not contain the necessary details to consider it as such).
Close-SmbOpenFile