1

using the below script I am able to get the blobs but since I have more than 5000 items so need to use next marker to get all the result so needed a help forming $stringtosign for marker and $URL for next marker. Need help with code inside If ($nextMarker) . Reference : https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs

$StorageAccount = 'xxxxxxx' 
$ContainerName = 'xxxxxx' 
$accesskey = 'xxxxxxxxxxxxx'

$date = [System.DateTime]::UtcNow.ToString("R",[Globalization.CultureInfo]::InvariantCulture)

$version = '2019-12-12'
$stringToSign = "GET`n`n`n`n`n`n`n`n`n`n`n`n"+
           "x-ms-date:$date`nx-ms-version:$version`n"+
           "/$StorageAccount/$ContainerName`ncomp:list`nrestype:container" 
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Convert]::FromBase64String($accesskey)
$signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
$signature = [Convert]::ToBase64String($signature)

$headers=@{"x-ms-date"=$date;
           "x-ms-version"= $version;
           "Authorization"= "SharedKey $($storageAccount):$signature";
           "ContentType"="application/xml"
}


$URI = "https://$StorageAccount.blob.core.windows.net/" + $ContainerName + "?restype=container&comp=list"

$blobs = Invoke-RestMethod -method GET -Uri $URI -Headers $headers

$Result = [xml]($blobs -replace '',"")
#$Result.EnumerationResults.Blobs.Blob | % {$length = $length + $_.Properties.'Content-Length'}

$NextMarker = $Result.EnumerationResults.NextMarker

If ($NextMarker){

$stringToSign = "GET`n`n`n`n`n`n`n`n`n`n`n`n"+
           "x-ms-date:$date`nx-ms-version:$version`n"+
"/$StorageAccount/$ContainerName`ncomp:list`n`nrestype:container`nmarker:$NextMarker`nmaxresults:5000" 
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Convert]::FromBase64String($accesskey)
$signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
$signature = [Convert]::ToBase64String($signature)

$headers=@{"x-ms-date"=$date;
           "x-ms-version"= $version;
           "Authorization"= "SharedKey $($storageAccount):$signature";
           "ContentType"="application/xml"
}


$URI = "https://$StorageAccount.blob.core.windows.net/" + $ContainerName + "?restype=container&comp=listmarker=$NextMarker&maxresults=5000"

$blobs = Invoke-RestMethod -method GET -Uri $URI -Headers $headers



}
1
  • Hello, have you solved the issue? If the answer is helpful, could you please accept it as answer? Thanks:). Commented Nov 27, 2020 at 0:40

1 Answer 1

0

In the If ($NextMarker){ } code block, please replace the $stringToSign filed with the following one:

$stringToSign = "GET`n`n`n`n`n`n`n`n`n`n`n`n"+
           "x-ms-date:$date`nx-ms-version:$version`n"+
           "/$StorageAccount/$ContainerName`ncomp:list`nmarker:$NextMarker`nmaxresults:5000`nrestype:container"

no other more changes. It works fine at my side.

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.