Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.27k stars 3.87k forks source link

Get-AzDataLakeGen2ChildItem - Example# 3 script will not loop through if a batch returns all folders #16047

Open rjallaMSFT opened 3 years ago

rjallaMSFT commented 3 years ago

Hello Team,

"if($items.Length -le 0) { Break;}" - This code line will break if ALL items in a batch are directories and the total length of a directory is zero. So the loop will not continue further.

Right code: `$MaxReturn = 1000 $FileSystemName = "filesystem1" $Total = 0 $Token = $Null do { $items = Get-AzDataLakeGen2ChildItem -FileSystem $FileSystemName -Recurse -MaxCount $MaxReturn -ContinuationToken $Token $Total += $items.Count

if($items.Length -le 0) { Break;} #Wrong line of code

 if($items.Count -le 0) { Break;} #right check
 $Token = $items[$items.Count -1].ContinuationToken;

} While ($Token -ne $Null) Echo "Total $Total items in Filesystem $FileSystemName"`


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ghost commented 3 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @sumantmehtams.

Issue Details
Hello Team, "if($items.Length -le 0) { Break;}" - This code line will break if ALL items in a batch are directories and the total length of a directory is zero. So the loop will not continue further. **Right code:** `$MaxReturn = 1000 $FileSystemName = "filesystem1" $Total = 0 $Token = $Null do { $items = Get-AzDataLakeGen2ChildItem -FileSystem $FileSystemName -Recurse -MaxCount $MaxReturn -ContinuationToken $Token $Total += $items.Count #if($items.Length -le 0) { Break;} #Wrong line of code if($items.Count -le 0) { Break;} #right check $Token = $items[$items.Count -1].ContinuationToken; } While ($Token -ne $Null) Echo "Total $Total items in Filesystem $FileSystemName"` --- #### Document Details ⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.* * ID: ea3aefec-aa47-3c4f-ba8c-410dfc302440 * Version Independent ID: af081e5c-e7db-04eb-0a2e-61e0f5b8c2e6 * Content: [Get-AzDataLakeGen2ChildItem (Az.Storage)](https://docs.microsoft.com/en-us/powershell/module/az.storage/get-azdatalakegen2childitem?view=azps-6.4.0&source=docs#example-3--list-items-recursively-from-a-filesystem-in-multiple-batches) * Content Source: [src/Storage/Storage.Management/help/Get-AzDataLakeGen2ChildItem.md](https://github.com/Azure/azure-powershell/blob/main/src/Storage/Storage.Management/help/Get-AzDataLakeGen2ChildItem.md) * Service: **storage** * GitHub Login: @dcaro * Microsoft Alias: **dcaro**
Author: rjallaMSFT
Assignees: -
Labels: `Service Attention`, `Data Lake Storage Gen2`
Milestone: -