Azure / Azure/azure-powershell

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

Open Beginner friendly
#16,047 2 comments 0 reactions 0 assignees View on GitHub
act-codegen-extensibility-squad Data Lake Storage Gen2 Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

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**

Contributor guide

Open the contributing guide

Research direction

Open src/Storage/Storage.Management/help/Get-AzDataLakeGen2ChildItem.md and inspect Example 3's batching loop. Verify the termination check against the reported folder-only batch case; done means the example continues through batches when the returned items are directories and stops only when the collection count is zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.