i often have the problem that when im trying to update some data on a networkdrive, other people have that exact file open without working on it, since its taking way to long to tell everyone to close the file i decided to write a tool that automatically disconnects everyone from the networkdrive. I have most of it done but the actual disconnect isnt really working , i am connecting to the server containing the networkdrives via PSSession
and tried using Close-Smbsession
and Close-Smbfile
but neither of them does work (the file wont actually close ) is there a different command that i dont know of that will actually fully close the file or the connection ?
CodePudding user response:
This is expected behaviour as Close-SmbOpenFile
only closes the open file handle and not the application that is holding the handle too.
The file will stay open for the end user (even though the file handle has been removed) and a new handle to the file will be created when they attempt to save the file.
This does mean that while there are no handles to the file (since you just closed them) you can edit it freely.