Skip to content

Instantly share code, notes, and snippets.

@danieljurek
Created November 19, 2023 05:27
Show Gist options
  • Save danieljurek/a87cb401b534482f37d83dd650068a91 to your computer and use it in GitHub Desktop.
Save danieljurek/a87cb401b534482f37d83dd650068a91 to your computer and use it in GitHub Desktop.
PowerShell: Use az CLI to list all blobs in a container
param(
$AccountName,
$ContainerName
)
$allBlobs = @()
$marker = ''
while($true) {
$blobResult = az storage blob list `
--account-name $AccountName `
--container-name $ContainerName `
--auth-mode login `
--num-results 5000 `
--marker "$marker" 2>&1
# Stderr has the marker
$markerOutput = $blobResult.Where({ $_ -is [System.Management.Automation.ErrorRecord]})
# Normal output has the
$blobs = $blobResult.Where({ $_ -isnot [System.Management.Automation.ErrorRecord]}) `
| ConvertFrom-Json -AsHashtable
$allBlobs += $blobs
if (!$markerOutput) {
# No next marker, quit
break
}
# Example output -
# WARNING: Next Marker:
# WARNING: <marker>
# Fetches <marker> from the output
$marker = ($markerOutput[1] -split ' ')[1]
if (!$marker) {
# No next marker, quit
break
}
}
return $allBlobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment