Last active
February 21, 2024 16:44
-
-
Save paratz/e2ea6427e5d5b8a0d43a9ee936b6d5a8 to your computer and use it in GitHub Desktop.
PowerShell script that exports the list of blobs in all containers in an Azure storage account with its name, modified date, size, and container name to a CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Set the storage account context | |
| $storageAccount = Get-AzStorageAccount -ResourceGroupName <resource-group-name> -Name <storage-account-name> | |
| $ctx = $storageAccount.Context | |
| # Get the list of containers | |
| $containers = Get-AzStorageContainer -Context $ctx | |
| # Create an empty array to store the list of blobs | |
| $blobs = @() | |
| # Loop through each container and get the list of blobs | |
| foreach ($container in $containers) { | |
| $containerBlobs = Get-AzStorageBlob -Container $container.Name -Context $ctx | |
| $containerBlobs | Add-Member -MemberType NoteProperty -Name Container -Value $container.Name | |
| $blobs += $containerBlobs | |
| } | |
| # Export the list of blobs to a CSV file | |
| $blobs | Select-Object Name, LastModified, Length, Container | Export-Csv -Path <csv-file-path> | |
| #Replace the following placeholders with your own values: | |
| #- `<resource-group-name>` with the name of your resource group. | |
| #- `<storage-account-name>` with the name of your storage account. | |
| #- `<csv-file-path>` with the path and file name for the CSV file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment