Pritesh Tayade
Pritesh Tayade

Reputation: 630

Getting more information on Azure File share file handles - Get-AzStorageFileHandle

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

https://github.com/Azure/azure-powershell/blob/master/src/Storage/Storage.Management/help/Get-AzStorageFileHandle.md#example-1-list-all-file-handles-on-a-file-share-recursively-and-sort-by-clientip-and-opentime

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

Answers (1)

Tom Luo
Tom Luo

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:

enter image description here

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

Related Questions