Created
November 9, 2021 01:43
-
-
Save tabs-not-spaces/83500c1cfffc09ed1ccf5338e265c54d to your computer and use it in GitHub Desktop.
template for batch handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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