Skip to content

Instantly share code, notes, and snippets.

@tabs-not-spaces
Created November 9, 2021 01:43
Show Gist options
  • Save tabs-not-spaces/83500c1cfffc09ed1ccf5338e265c54d to your computer and use it in GitHub Desktop.
Save tabs-not-spaces/83500c1cfffc09ed1ccf5338e265c54d to your computer and use it in GitHub Desktop.
template for batch handling
$objects = (0..273)
$batchValue = 20
$result = New-Object System.Collections.ArrayList
$id = 1
for ($i = 0; $i -lt $objects.Count; $i += $batchValue) {
$start = $i + 1
$end = ($i + 19) -gt $objects.Count ? $objects.count : $i + 19
$progressParams = @{
Activity = "Testing.."
Status = "Processing batch $start - $end of $($objects.count)"
PercentComplete = $(($end / $objects.count) * 100)
}
Write-Progress @progressParams
$batchBody = @{
batch = $id
content = $objects[$i..($end)]
}
$batchBody.contentCount = $batchBody.content.Count
[void]$result.Add($batchBody)
$id ++
Start-Sleep -Milliseconds 100
}
$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment