Microsoft Fabric Updates Blog

Getting the size of OneLake data items or folders

Understanding the size of your OneLake data can be important to manage and plan storage costs, especially if you have large amounts of data.  Today, capacity admins can use the Microsoft Fabric Capacity Metrics app to find the total size of OneLake data stored in a given capacity or workspace but you may also want to understand the size of data in a specific item or folder.  In this blog, we’ll walk through a couple Azure PowerShell commands that enable you to get size information of any item or folders in OneLake.  As described in this blog post, with OneLake’s compatibility with ADLS tools, it’s as simple as replacing the ADLS Gen2 URL with a OneLake URL. 

To get started, there are three simple steps to set up:

Step 1: Open Azure PowerShell and install the Azure Storage PowerShell module. 

Install-Module Az.Storage -Repository PSGallery -Force

Step 2: Sign in to your Azure account.

Connect-AzAccount

Step 3: Create the storage account context.

  • Storage account name is onelake.
  • Set -UseConnectedAccount to pass through your Azure credentials.
    • Set -endpoint as fabric.microsoft.com.
$ctx = New-AzStorageContext -StorageAccountName 'onelake' -UseConnectedAccount -endpoint 'fabric.microsoft.com'

Get the size of an item

This example gets the size of an item “mylakehouse.lakehouse” in the workspace “myworkspace”.   

$workspaceName = 'myworkspace'
$itemPath = 'mylakehouse.lakehouse'
$colitems = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $workspaceName -Path $itemPath -Recurse -FetchProperty | Measure-Object -property Length -sum
"Total file size: " + ($colitems.sum / 1GB) + " GB"

Keep in mind, if the workspace name does not meet Azure Storage naming criteria (ex. must be lowercase letters) then replace the workspace and item names with their GUIDs.  You can find the associated GUID for your workspace or item in the URL on the Fabric portal. You must use GUIDs for both the workspace and the item, and don’t need the item type.

Get the size of a folder

$workspaceName = 'myworkspace'
$itemPath = 'mylakehouse.lakehouse/Files/folder1'
$colitems = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $workspaceName -Path $itemPath -Recurse -FetchProperty | Measure-Object -property Length -sum
"Total file size: " + ($colitems.sum / 1GB) + " GB"

Additional Details

  • These PowerShell commands won’t work on shortcuts that directly point to ADLS containers.  It’s recommended you create ADLS shortcuts to a directory that is at least one level below a container.
  • If you would like to fully automate these steps, you can obtain the workspace and item information with these APIs: Workspaces – List Workspaces – REST API and Items – List Items – REST API.

Next steps

We hope you continue to explore the ways you can leverage ADLS tools and APIs with your OneLake data.  To learn more about how to connect to OneLake, check out these links:

Related blog posts

Getting the size of OneLake data items or folders

September 25, 2024 by Idris Motiwala

Overview This blog will walk thru the new capabilities in Mirroring Azure SQLDB in Fabric since our public preview announcement earlier in March 2024. Today, we also announced general availability of Mirroring for Snowflake in Microsoft Fabric. To recap, the 3 key benefits of Mirroring are: Over the past few months, we’ve removed limitations to … Continue reading “Mirroring Azure SQLDB – new features and what’s coming up?”

September 25, 2024 by Trevor Olson

GCS shortcuts and S3 Compatible shortcuts are now generally available. Utilize shortcuts in OneLake to quickly and easily make data accessible in Fabric. No need to set up pipelines or copy jobs, just create a shortcut and your data is immediately available in Fabric.    From your Lakehouse, select new shortcut. Choose your shortcuts type (GCS, … Continue reading “Google Cloud Storage shortcuts and S3 Compatible shortcuts generally available”