I'm not sure whether what you want to achieve would work using the Az PowerShell modules.
Based on @guiwhatsthat's note on using Select-String, you could use the REST API though. Technically it is also downloading the blob (but not storing in a file) - here is an example.
Authentication Part
This uses applicationId/secret based authentication. The corresponding Service Principal would need to have the Storage Blob Data Reader role assigned as a minimum.
$requestMethod = 'POST'
$requestHeaders = @{
'Content-Type' = 'application/x-www-form-urlencoded'
}
$requestUri = 'https://login.microsoftonline.com/'+$tenantId+'/oauth2/v2.0/token'
$requestBody = @{
client_id = $applicationId
grant_type = 'client_credentials'
client_secret = $applicationSecret
scope = $storageAccountBlobEndpoint+'.default'
}
$request = Invoke-RestMethod -Method $requestMethod `
-Headers $requestHeaders `
-Uri $requestUri `
-Body $requestBody
Read Blob and search for string
$blobRequestMethod = 'GET'
$blobRequestHeaders = @{
'Content-Type' = 'application/xml'
Authorization = $($request.token_type + ' ' + $request.access_token)
'x-ms-date' = $(Get-Date -AsUTC -Format 'ddd, dd MMM yyyy HH:mm:ss') + ' GMT'
'x-ms-version' = '2021-04-10'
}
$blobRequestUri = $storageAccountBlobEndpoint + $containerName + '/' + $blobName
$blobRequest = Invoke-RestMethod -Method $blobRequestMethod -Headers $blobRequestHeaders -Uri $blobRequestUri
$blobRequest | Select-String -Pattern $searchString
Obviously, you would need to populate some variables before running this (values below are random examples):
$tenantId = "597d8458-6a5d-447f-875d-922e448f681a"
$subscriptionId = "3338781b-426a-4b1c-8545-d9b88d78039d"
$storageAccountBlobEndpoint = "https://<some_name>.blob.core.windows.net/"
$applicationId = "4e625cb8-595b-4b46-9ba9-6a9d220f4208"
$applicationSecret = "<some_secret_value>"
$containerName = "container01"
$blobName = "yourblob.txt"
$searchString = "find this"
I know it is not without downloading data but at least it is not writing a file. :-)
Reference: https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob
"Value | Select-String -Pattern "Pattern". Additionaly you should specify what property you want to use of the of $lastblob. Otherwise it will always use the datatype (Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageBlob) of the object and not the value.