Hello @Rik Hunter ,
Can you try out the below sample script . While running pass the storage account name and the blob name to be searched.
Script will loop through all the containers in the storage account and search for the specific blob name passes as a paramter.
FYI - Script can be optimized much better instead of using embedded for loops. Right now the time complexity of the below script is O(n^2). I am sure this can be done in O(n).
Below module will search for a particular blob in all the containers of a specific storage account
param(
[Parameter(Mandatory)]$strAccountName,
[Parameter(Mandatory)]$BlobName
)
Function RecursiveSearchForABlobInAllContainers()
{
enter the subscriptionid
**#login to Azure Account**
**#Try to set the subscription context here or manually in the command prompt**
# Set-AzContext "SubID"
#Get all Azure storage accounts under the subscription
$AllStorageAccounts = Get-AzStorageAccount
#Loop through each storage account
Write-Host "Looping through all the Storage Accounts under the subscription"
foreach($stAcc in $AllStorageAccounts)
{
if ($stAcc.StorageAccountName -eq $strAccountName)
{
Write-Host "Reading Storage Account:" $stAcc.StorageAccountName -ForegroundColor "Yellow"
#Get the Storage account details under the resource group
try
{
$strAccount = Get-AzStorageAccount -ResourceGroupName $stAcc.ResourceGroupName -Name $stAcc.StorageAccountName
}
catch
{
Write-Host "Below error occured while accessing storage Account :- " $stAcc -ForegroundColor "Yellow"
Write-Host $Error
}
#Get the context
$context = $strAccount.Context
#Get the Container
try
{
$Containers = Get-AzStorageContainer -Context $context
}
catch
{
Write-Host "Below error occured while accessing storage Account :- " $stAcc -ForegroundColor "Yellow"
Write-Host $Error
}
#Loop through all the containers
foreach($container in $containers)
{
#Get all the blobs in the container
$blobData = Get-AzStorageblob -Container $container.Name -Context $context
#Loop through the blobs
foreach($blob in $blobData)
{
if ($blob.Name -match $BlobName) #it will match for a substring
{
Write-Host "Blob: " $BlobName " found under path: " $blob.Name -ForegroundColor Green
}
}
}
}
else
{
Write-Host "Storage Account:" $strAccountName " does not exist" -ForegroundColor Red
}
}
}
RecursiveSearchForABlobInAllContainers
Let us know if the above script helps you out to get started. If it is useful , Please make sure to "Upvote and Accept the Answer"