Search code examples
azureazure-blob-storageazure-storageazure-powershell

Azure Storage account API: List (recursive) only directories in account - not files


I want to be able to query an Azure storage account and pull back a list of only the directories/folders under a container, rather than the entire contents including blobs/files.

I want to do this so I can then export the ACLs for each of those folders.

I've tried a few options:

Get-AzDataLakeGen2ChildItem -Recurse returns all folders AND files. You can filter each item on IsDirectory -eq $true, but because of the maximum item limit, the need for a continuation token, and a generally slow response time, this takes a long time amount of time if your container has hundreds of thousands of files.

Using the storage API - querying the below endpoint - also returns all files/folders, with no way to filter the response.

https://STORAGEACCOUNT.blob.core.windows.net/CONTAINER?comp=list&prefix=one%2F&maxresults=5000&restype=container&include=metadata&delimiter=%2F


Solution

  • Not sure about PowerShell commands for this, but the API (docs) does support a showonly=directories parameter.

    This does require that you have hierarchical namespaces enabled, but I assume you do since you mentioned folder ACLs.