Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

PowerShell How to find file and folders in Azure Storage Account Blobs and Containers

This script helps to find files and folders on Azure Storage Accounts blobs and containers.

There are two PowerShell variables I have mentioned, First Variable is $searchFile use file extension or names you want to search. Report are generated in file path mentioned under variable $exportCsv.

$searchFile = 'txt|csv|ps1'
$exportCsv = 'c:\temp\files.csv'

$storageAccount = Get-AzStorageAccount
foreach ($sa in $storageAccount)
{
    $saKey = Get-AzStorageAccountKey -ResourceGroupName $sa.ResourceGroupName -Name $sa.StorageAccountName
    $saContext = New-AzStorageContext -StorageAccountName $sa.StorageAccountName -StorageAccountKey $saKey[1].Value
    $saContainer = Get-AzStorageContainer -Context $saContext
    foreach ($saFolder in $saContainer)
    {
        $files = Get-AzStorageBlob -container $saFolder.Name -Context $saContext | Where-Object {$_.Name -match $searchFile}
        $files
        $files | Select Name, @{N='StorageAccountName';E={$_.Context.StorageAccountName}}, @{N='Container';E={$saFolder.Name}} | Export-Csv -NoTypeInformation -Path $exportCsv -Append
    }
}

Download this Find-AzureBlobFile.ps1 file here or it is also available on github.com/janviudapi.

The real output shows on the console as well as its recorded in the given csv file path.

Microsoft Azure Powershell ISE Windows Get-azStorageBlob Get-azstorageAccount select-object Get-azstorageContainer get-azstoragecontext key.jpg

Useful Articles
Create and manage Azure budgets
Connect-AzAccount The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded
Microsoft Azure Rest API using PowerShell
Microsoft Azure Rest API using PowerShell Part 2
How to switch to other Azure AD tenant using PowerShell and Azure CLI
Creating a new user in Azure AD using oneliner PowerShell and Azure CLI
Connect-AzureAD: One or more errors occurred. Could not load type 'System.Security.Cryptography.SHA256Cng'
Create a Azure Virtual Network with Subnet using PowerShell
Azure add create a Subnet to existing Virtual Network using PowerShell
Remove Azure Virtual Network Subnet using PowerShell

Go Back

Comment

Blog Search

Page Views

10347999

Follow me on Blogarama