2

I have an object called $latestBlob_content, this contains logs from azure build pipeline. I want to find a specific string from this object. But when I call - $latestBlob_content | Select-String -Pattern $pattern . This returns the whole logs. Is the 3rd line right way of reading a blob file!?

$blobs = Get-AzStorageBlob -Container $container_name -Context $context | sort @{Expression = "LastModified";Descending=$true}
$latestBlob = $blobs[0]
$latestBlob_content = $latestBlob.ICloudBlob.DownloadText()
$pattern = "Terraform_modules.azure_data_lake.*"
$latestBlob_content | Select-String -Pattern $pattern

Thanks in advance

Code those are not working - $latestBlob_content.ToString() | Select-String -Pattern "Terraform_modules.azure_data_lake.*"

7
  • Select-String -InputObject $latestBlob_content -Pattern $pattern also returns whole logs. no the specified pattern string Commented Oct 13, 2022 at 11:04
  • Try this command Select-String -Path .\*.txt -Pattern 'Terraform_modules.azure_data_lake.*' Commented Oct 13, 2022 at 11:08
  • @RajkumarM , the blob is not in my drive. I am accessing it directly. I don't want to download the logs to my local drive Commented Oct 13, 2022 at 11:09
  • returns same result Commented Oct 13, 2022 at 11:12
  • Most likely, your $latestBlob_content is one string instead of an array of strings. You could check the type using $latestBlob_content.GetType(). If that is the case, you essentially pas 1 string to Select-String and ask it if the string contains your pattern and it does so it returns you back the complete string. You could try $latestBlob_content -split "`r?`n" | Select-String -Pattern $pattern Commented Oct 13, 2022 at 11:17

1 Answer 1

3

Most likely, your $latestBlob_content is one string instead of an array of strings.You could check the type using $latestBlob_content.GetType().

If that is the case, you are essentially passing one string to Select-String and ask it if the string contains your pattern. It does so it returns you back the complete string.

You could try following to split up your one string into an array of strings and select only those who match your pattern

$latestBlob_content -split "`r?`n" | Select-String -Pattern $pattern
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.