Created
November 3, 2017 17:52
-
-
Save kevinhillinger/72ff39c1ed57694d05cbbccb8b7852d2 to your computer and use it in GitHub Desktop.
Using ListBlobsSegmented to page through Azure Blob Storage results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the container | |
$account = Get-AzureRmStorageAccount -Name blobiterationtest0 -ResourceGroupName blob-iteration-test | |
$context = $account.Context | |
$container = Get-AzureStorageContainer -Context $context -Name test | |
$maxResults = 5 | |
$segment = 0 #which segment / result set are we getting? (zero index) | |
function getBlobs($segment) { | |
$blobPrefix = $null | |
$useFlatBlobListing = $true | |
$blobListingDetails = [Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails]::Metadata | |
$continuationToken = $null | |
$operationContext = New-Object -TypeName Microsoft.WindowsAzure.Storage.OperationContext | |
$blobRequestOptions = New-Object -TypeName Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions | |
$blobResultSegment = $null | |
$isLasResultSet = $false | |
for ($i = 0; $i -le $segment; $i++) { | |
if ($isLasResultSet) { | |
$blobResultSegment = $null | |
break; | |
} | |
$blobResultSegment = $container.CloudBlobContainer.ListBlobsSegmented( | |
$blobPrefix, | |
$useFlatBlobListing, | |
$blobListingDetails, | |
$maxResults, | |
$continuationToken, | |
$blobRequestOptions, | |
$operationContext | |
) | |
$continuationToken = $blobResultSegment.ContinuationToken | |
if ($continuationToken -eq $null) { # no results remaining | |
$isLasResultSet = $true; | |
} | |
} | |
return $blobResultSegment.Results | |
} | |
# now operate on the blobs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment