Reputation: 630
I have got the open file handles from azure storage account file share, but this information seems to be very less to understand what Process has started it or On which file this file handle is.
Getting file handles https://learn.microsoft.com/en-us/powershell/module/az.storage/get-azstoragefilehandle?view=azps-2.7.0
How to get more information using handleid or sessionid from this list?
I have searched a lot on azure docs as well as on internet but no information on this.
Sample script and response :
PS C:\>Get-AzStorageFileHandle -ShareName "mysharename" -Recursive | Sort-Object ClientIP,OpenTime
HandleId Path ClientIp ClientPort OpenTime LastReconnectTime FileId ParentId SessionId
-------- ---- -------- ---------- -------- ----------------- ------ -------- ---------
28506980357 104.46.105.229 49805 2019-07-29 08:37:36Z 0 0 9297571480349046273
28506980537 dir1 104.46.105.229 49805 2019-07-30 09:28:48Z 10376363910205800448 0 9297571480349046273
Upvotes: 1
Views: 4854
Reputation: 612
After a quick research and local test, I believe the "Path" returned by the command is the file or directory path you are looking for. File handle is not only for file but also for folder. The trick here is the handle for file is not being hold always. In fact, most applications release the file handle as soon as they open the file, like notepad. So when you run the command, for the most of time, you could only see handle for folder, not files.
To verify this, I've tested with the code below:
static void Main(string[] args)
{
string path = args[0];
var file=File.Open(path, FileMode.OpenOrCreate);
Console.WriteLine("Press any key to release the handle");
Console.ReadKey();
file.Close();
}
When excuting File.Open
, the process holds handle, then I run Get-AzStorageFileHandle
. The handle for "test.csv" is displayed:
But if you open the file with notepad, only handle for folder is displayed.
Anyway, you can use the "path" returned to determine which file is being held by others.
By the way, the handle.exe is not applied for cloud environment. You should not use it.
Upvotes: 1