List All file Share and backup information April 7, 2025 by admin
This PowerShell script is written to connect to Azure, loop through all subscriptions under a specific tenant, and for each storage account in each subscription, list each File Share and information about backup for each of them.
Connect-AzAccount
$allContext = Get-AzSubscription | Where-Object { $_.TenantId -eq "xxxx" }
foreach ( $context in $allContext ) {
Select-AzSubscription -SubscriptionId $context.id
$storageAccount = ""
$a= ""
$storageAccount = Get-AzStorageAccount
foreach ($storage in $storageAccount)
{
$ctx=(Get-AzStorageAccount -ResourceGroupName $storage.ResourceGroupName -Name $storage.StorageAccountName).Context
$shares = Get-AZStorageShare -Context $ctx | Sort-Object Name,SnapshotTime -Descending
$shares = $shares | Group-Object Name | ForEach-Object { $_.Group | Select-Object -First 1 }
# $shares
Foreach ( $share in $shares ) {"FileShare;"+$context.Name+";"+$storage.ResourceGroupName+";"+$storage.StorageAccountName+";"+$share.Name+";"+$share.IsSnapshot+";"+$share.LastModified }
}
}