Closing All Shared Files on the Network

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












I am trying to close all of the open files in the shared folders of a server via PowerShell script. I found the following script which only close files on one drive (F:), however, this server has 3 drives (F:, G:, H:) which I want to close all.



net files | 
where $_.Contains( "F:" ) |
foreach $_.Split( ' ' )[0] |
foreach net file $_ /close


Is there a way to add missing drives into this script or I have to use the same script separately for each drive?



I tried $_.Contains( "F:", "G:", "H:" ) but didn't work



Thank you for your help!










share|improve this question







New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2




    Possible duplicate of Close locked file in Windows Share using Powershell and Openfiles Get-SmbOpenFile | Close-SmbOpenFile being the important part for all files.
    – Lenniey
    5 hours ago















up vote
2
down vote

favorite
1












I am trying to close all of the open files in the shared folders of a server via PowerShell script. I found the following script which only close files on one drive (F:), however, this server has 3 drives (F:, G:, H:) which I want to close all.



net files | 
where $_.Contains( "F:" ) |
foreach $_.Split( ' ' )[0] |
foreach net file $_ /close


Is there a way to add missing drives into this script or I have to use the same script separately for each drive?



I tried $_.Contains( "F:", "G:", "H:" ) but didn't work



Thank you for your help!










share|improve this question







New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2




    Possible duplicate of Close locked file in Windows Share using Powershell and Openfiles Get-SmbOpenFile | Close-SmbOpenFile being the important part for all files.
    – Lenniey
    5 hours ago













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I am trying to close all of the open files in the shared folders of a server via PowerShell script. I found the following script which only close files on one drive (F:), however, this server has 3 drives (F:, G:, H:) which I want to close all.



net files | 
where $_.Contains( "F:" ) |
foreach $_.Split( ' ' )[0] |
foreach net file $_ /close


Is there a way to add missing drives into this script or I have to use the same script separately for each drive?



I tried $_.Contains( "F:", "G:", "H:" ) but didn't work



Thank you for your help!










share|improve this question







New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to close all of the open files in the shared folders of a server via PowerShell script. I found the following script which only close files on one drive (F:), however, this server has 3 drives (F:, G:, H:) which I want to close all.



net files | 
where $_.Contains( "F:" ) |
foreach $_.Split( ' ' )[0] |
foreach net file $_ /close


Is there a way to add missing drives into this script or I have to use the same script separately for each drive?



I tried $_.Contains( "F:", "G:", "H:" ) but didn't work



Thank you for your help!







powershell network-share shell-scripting






share|improve this question







New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 5 hours ago









eccoripo

132




132




New contributor




eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






eccoripo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2




    Possible duplicate of Close locked file in Windows Share using Powershell and Openfiles Get-SmbOpenFile | Close-SmbOpenFile being the important part for all files.
    – Lenniey
    5 hours ago













  • 2




    Possible duplicate of Close locked file in Windows Share using Powershell and Openfiles Get-SmbOpenFile | Close-SmbOpenFile being the important part for all files.
    – Lenniey
    5 hours ago








2




2




Possible duplicate of Close locked file in Windows Share using Powershell and Openfiles Get-SmbOpenFile | Close-SmbOpenFile being the important part for all files.
– Lenniey
5 hours ago





Possible duplicate of Close locked file in Windows Share using Powershell and Openfiles Get-SmbOpenFile | Close-SmbOpenFile being the important part for all files.
– Lenniey
5 hours ago











1 Answer
1






active

oldest

votes

















up vote
5
down vote



accepted










The command you are using is not a native PowerShell command. However, PowerShell does come with a lot of functions to control SMB connections and shares.



What you are looking for could be this:



Get-SMBOpenFile | Close-SMBOpenFile -Force


This will close all files opened via file shares. You can also manage SMB Connections (Get-SMBConnection) and other things. With Get-Command *smb* you will get a list of all SMB related commands.






share|improve this answer






















  • Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
    – eccoripo
    2 hours ago











  • Add the -Force parameter to the close command. I added it into my answer.
    – Tobias
    2 hours ago










  • And.. that works. Thank you!
    – eccoripo
    2 hours ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






eccoripo is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f937710%2fclosing-all-shared-files-on-the-network%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted










The command you are using is not a native PowerShell command. However, PowerShell does come with a lot of functions to control SMB connections and shares.



What you are looking for could be this:



Get-SMBOpenFile | Close-SMBOpenFile -Force


This will close all files opened via file shares. You can also manage SMB Connections (Get-SMBConnection) and other things. With Get-Command *smb* you will get a list of all SMB related commands.






share|improve this answer






















  • Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
    – eccoripo
    2 hours ago











  • Add the -Force parameter to the close command. I added it into my answer.
    – Tobias
    2 hours ago










  • And.. that works. Thank you!
    – eccoripo
    2 hours ago














up vote
5
down vote



accepted










The command you are using is not a native PowerShell command. However, PowerShell does come with a lot of functions to control SMB connections and shares.



What you are looking for could be this:



Get-SMBOpenFile | Close-SMBOpenFile -Force


This will close all files opened via file shares. You can also manage SMB Connections (Get-SMBConnection) and other things. With Get-Command *smb* you will get a list of all SMB related commands.






share|improve this answer






















  • Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
    – eccoripo
    2 hours ago











  • Add the -Force parameter to the close command. I added it into my answer.
    – Tobias
    2 hours ago










  • And.. that works. Thank you!
    – eccoripo
    2 hours ago












up vote
5
down vote



accepted







up vote
5
down vote



accepted






The command you are using is not a native PowerShell command. However, PowerShell does come with a lot of functions to control SMB connections and shares.



What you are looking for could be this:



Get-SMBOpenFile | Close-SMBOpenFile -Force


This will close all files opened via file shares. You can also manage SMB Connections (Get-SMBConnection) and other things. With Get-Command *smb* you will get a list of all SMB related commands.






share|improve this answer














The command you are using is not a native PowerShell command. However, PowerShell does come with a lot of functions to control SMB connections and shares.



What you are looking for could be this:



Get-SMBOpenFile | Close-SMBOpenFile -Force


This will close all files opened via file shares. You can also manage SMB Connections (Get-SMBConnection) and other things. With Get-Command *smb* you will get a list of all SMB related commands.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 5 hours ago









Tobias

579719




579719











  • Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
    – eccoripo
    2 hours ago











  • Add the -Force parameter to the close command. I added it into my answer.
    – Tobias
    2 hours ago










  • And.. that works. Thank you!
    – eccoripo
    2 hours ago
















  • Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
    – eccoripo
    2 hours ago











  • Add the -Force parameter to the close command. I added it into my answer.
    – Tobias
    2 hours ago










  • And.. that works. Thank you!
    – eccoripo
    2 hours ago















Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
– eccoripo
2 hours ago





Yep, it works. However, I get a confirmation window (Are you sure you want to perform this action?). Is there a way to override it?
– eccoripo
2 hours ago













Add the -Force parameter to the close command. I added it into my answer.
– Tobias
2 hours ago




Add the -Force parameter to the close command. I added it into my answer.
– Tobias
2 hours ago












And.. that works. Thank you!
– eccoripo
2 hours ago




And.. that works. Thank you!
– eccoripo
2 hours ago










eccoripo is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















eccoripo is a new contributor. Be nice, and check out our Code of Conduct.












eccoripo is a new contributor. Be nice, and check out our Code of Conduct.











eccoripo is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f937710%2fclosing-all-shared-files-on-the-network%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

What does second last employer means? [closed]

One-line joke