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.