If you're using this azure cli command: az storage fs file list, the next_marker
is not returned to the variable $files
, it's always printed out in the console. You need to copy and paste it.
As a workaround, you can use this azure cli command: az storage blob list(Most of the azure blob storage
cli commands are also available in ADLS Gen2
). This command has a parameter --show-next-marker
, you can use it to return next_marker
to a variable.
I write an azure cli scripts and it can work well for ADLS Gen2
:
$next_token = ""
$blobs=""
$response = & az storage blob list --container-name your_file_system_in_ADLS_Gen2 --account-name your_ADLS_Gen2_account --account-key your_ADLS_Gen2_key --num-results 5 --show-next-marker | ConvertFrom-Json
$blobs += $response.properties.contentLength
$next_token = $response.nextMarker
while ($next_token -ne $null){
$response = & az storage blob list --container-name your_file_system_in_ADLS_Gen2 --account-name your_ADLS_Gen2_account --account-key your_ADLS_Gen2_key --num-results 5 --marker $next_token --show-next-marker | ConvertFrom-Json
$blobs = $blobs + " " + $response.properties.contentLength
$next_token = $response.nextMarker
}
$blobs
The test result:

Please note that upgrade your azure cli to the latest version, the --show-next-marker
parameter may not work in the old versions as per this issue.