I was doing a PowerShell script for a quicker way of closing locked files on a big Windows Server 2008 R2 file server (more than 2500 files opened at this moment, and the peak hour was like 3-4 hours ago), and I'd to choose between net files
or openfiles
. So I went with openfiles
as is newer and it can give the full path of the file (net files
can do that too, but you've to query every single ID).
I was having problems with it: some files won't close. I checked with net files, and all was ok... So I've started to take a closer look, and this is (an excerpt of) what I've found:
C:\> net files
ID Path User name # Locks
-------------------------------------------------------------------------------
3221368833 G:\Users\... SomeUser 3
2550215683 G:\Users\... SomeUser 3
3422797829 G:\Users\... SomeUser 0
805310474 F:\Recursos\... SomeUser 3
335585292 G:\Users\SomeUser\My Documents SomeUser 0
4026636306 G:\Users\SomeUser\Desktop SomeUser 0
2684396568 G:\Users\... SomeUser 0
2952839192 G:\Users\...\EXCEL\SomeFolder2016 SomeUser 0
4160993304 G:\Users\... SomeUser 0
1610613364 F:\Recursos\Suministros SomeUser 0
The command completed successfully.
C:\> openfiles /query /v
Files opened remotely via local share points:
---------------------------------------------
Hostname ID Accessed By Type #Locks Open Mode Open File (Path\executable)
=============== ======== ==================== ========== ========== =============== ============================================================================
MyServer 32213688 SomeUser Windows 3 Write + Read G:\Users\SomeUser\My Documents\[SomePath].XLS
MyServer 25502156 SomeUser Windows 3 Write + Read G:\Users\SomeUser\My Documents\[SomePath].xls
MyServer 34227978 SomeUser Windows 0 Write + Read G:\Users\SomeUser\My Documents\[SomePath].xls
MyServer 80531047 SomeUser Windows 3 Write + Read F:\Recursos\Suministros\[SomePath].xls
MyServer 33558529 SomeUser Windows 0 Read G:\Users\SomeUser\My Documents
MyServer 40266363 SomeUser Windows 0 Read G:\Users\SomeUser\Desktop
MyServer 26843965 SomeUser Windows 0 Write + Read G:\Users\SomeUser\My Documents\[SomePath].XLS
MyServer 29528391 SomeUser Windows 0 Read G:\Users\SomeUser\My Documents\EXCEL\SomeFolder2016
MyServer 41609933 SomeUser Windows 0 Write + Read G:\Users\SomeUser\My Documents\[SomePath].XLS
MyServer 16106133 SomeUser Windows 0 Read F:\Recursos\Suministros
Wait, the IDs are different... Hell, no, the openfiles
IDs are truncated!!
So obviously for the script itself, I'm for the moment going for net files
, get the IDs, query each single ID so I get the full path, and from there I can reuse the rest of the script.
But for the sake of my sanity: is this a bug? A feature? Windows Server 2008 R2 is not new, and I was not able to find any reference to this, not to talk about a hotfix!
So three years later, I've found an answer and a solution, or workaround: this is a bug of the default output of
openfiles
, which istable
. If you specify the options/FO CSV
or/FO List
, IDs are complete.