Manage OneLake with PowerShell

Microsoft Fabric OneLake integrates with the Azure PowerShell module for data reading, writing, and management.

Connect to OneLake with Azure PowerShell

Connect to OneLake from PowerShell by following these steps:

  1. Install the Azure Storage PowerShell module.

    Install-Module Az.Storage -Repository PSGallery -Force
    
  2. Sign in to your Azure account.

    Connect-AzAccount
    
  3. Create the storage account context.

    • Storage account name is onelake.
    • Set -UseConnectedAccount to passthrough your Azure credentials.
    • Set -endpoint as fabric.microsoft.com.
  4. Run the same commands used for Azure Data Lake Storage (ADLS) Gen2. For more information about ADLS Gen2 and the Azure Storage PowerShell module, see Use PowerShell to manage ADLS Gen2.

Example: Get the size of an item or directory

Install-Module Az.Storage -Repository PSGallery -Force
Connect-AzAccount
$ctx = New-AzStorageContext -StorageAccountName 'onelake' -UseConnectedAccount -endpoint 'fabric.microsoft.com' 

# This example uses the workspace and item name. If the workspace name does not meet Azure Storage naming criteria (no special characters), you can use GUIDs instead.
$workspaceName = 'myworkspace'
$itemPath = 'mylakehouse.lakehouse/Files'

# Recursively get the length of all files within your lakehouse, sum, and convert to GB.
$colitems = Get-AzDataLakeGen2ChildItem -Context $ctx -FileSystem $workspaceName -Path $itemPath -Recurse -FetchProperty | Measure-Object -property Length -sum
"Total file size: " + ($colitems.sum / 1GB) + " GB"