I am using Get-SmbOpenFile, But surprisingly, it looses its connection and I can see that there is no lock even after couple of seconds later on the file any more, even it is still opened. I safely can remove that file on my server.
Why, this can be? I have to check opened .VHDX disk file connected with user and need to close them if they are still opened.
Get-SmbOpenFile | Where-Object { $._Path -match '\\apvdp100\Profile\TestP1088\100.txt' } returns nothing even the file is opened remotely.
Get-SmbOpenFile | Where-Object { $._Path -match '100.txt' } returns the object if i open the file remotely and check within a second or so and stops outputting after few tries. Sometimes, even immediately issueing `Get-SmbOpenFile` doesn't outputs anything at all.
So, I have two questions :-)
So, what is the right way to search the file ? ( above Fully qualified path doesnt returns the search result )
Why the lock gets lost after couple of seconds later
Thanks for valuable comments @Greg Askew. You are right. It must be noted which application in particular locks the file. Notepad and .rtf files are not maintaining the locks and therefore they are not good use cases for testing these scenarios.
I later focused on '.VHDX' based files and mounted them for testing above command let which returned expected results accordingly.