storage account : request help with getting a list of Filshares and their size in GB

Carl Lewis (Cloud Admin) 0 Reputation points
2024-08-19T01:46:40.49+00:00

Request for assistance for powershell Script to report on azure file shares and size of each folder.

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,283 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,116 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Nehruji R 7,556 Reputation points Microsoft Vendor
    2024-08-20T06:19:10.6666667+00:00

    Hello Carl Lewis (Cloud Admin),

    Greetings! Welcome to Microsoft Q&A Platform.

    Please try the below PowerShell script that reports on Azure file shares and the size details,

    Load the Azure PowerShell module
    Import-Module Az
    
    Function to get file share usage information
    function Get-FileShareUsage {
    
    param(
    
    [Parameter(Mandatory=$true)]
    
    [string]$ResourceGroupName,
    
    [Parameter(Mandatory=$true)]
    
    [string]$StorageAccountName,
    
    [Parameter(Mandatory=$true)]
    
    [string]$ShareName
    
    )
    
    try {
    
    $share = Get-AzRmStorageShare -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName -Name $ShareName -GetShareUsage
    
    $shareUsageGB = [math]::Round($share.ShareUsageBytes / 1GB, 2)
    
    $share | Select-Object ResourceGroupName, StorageAccountName, Name, QuotaGiB, EnabledProtocols, AccessTier, Deleted, Version, @{Name="ShareUsageGB"; Expression={$shareUsageGB}}
    
    } catch {
    
    Write-Warning "Error retrieving file share usage: $($_.Exception.Message)"
    
    $null
    
    }
    
    }
    
    Initialize an array to hold the results
    $results = @()
    
    Get all resource groups
    $resourceGroups = Get-AzResourceGroup
    
    foreach ($resourceGroup in $resourceGroups) {
    
    Get storage accounts in the resource group
    $storageAccounts = Get-AzStorageAccount -ResourceGroupName $resourceGroup.ResourceGroupName
    
    foreach ($storageAccount in $storageAccounts) {
    
    Get file shares for the storage account
    $fileShares = Get-AzRmStorageShare -ResourceGroupName $resourceGroup.ResourceGroupName -StorageAccountName $storageAccount.StorageAccountName
    
    foreach ($fileShare in $fileShares) {
    
    $fileShareUsage = Get-FileShareUsage -ResourceGroupName $resourceGroup.ResourceGroupName -StorageAccountName $storageAccount.StorageAccountName -ShareName $fileShare.Name
    
    if ($fileShareUsage) {
    
    Add the usage information to the results array
    $results += $fileShareUsage
    
    }
    
    }
    
    }
    
    }
    
    Format the results for console display
    $results | Format-Table -AutoSize
    
    Export the results to a CSV file
    $results | Export-Csv -Path "FileShareUsage.csv" -NoTypeInformation
    
    
    

    Replace "YourResourceGroupName", "YourStorageAccountName", and "YourFileShareName" with your actual Azure resource group name, storage account name, and file share name.

    Hope this answer helps! Please let us know if you have any further queries. I’m happy to assist you further.


    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.