Powershell 7.21 stops working with Numbers higher than 100,000 (ForEach-Object)

Viewed 48

To stress test a Storage Account in Azure, I want to create Millions of Dummy data. I use Powershell for that:

Create Random files

1..100000 | ForEach-Object -Parallel {
    $file = New-Item -Path . -Name "file$_" -ItemType "file" -Value (New-Guid).Guid
    azcopy copy $file.FullName $using:sasUrl | Out-Null
    Remove-Item -Path $file.FullName -Force
} -ThrottleLimit 20

When I create 100000, the script works as designed. But when I add 1,000,000 - Powershell stops working after creating a couple of files. It just freeze. It doesn't throw any error.

Works:         1..100000 | ForEach-Object {}
Won't work:    1..1000000 | ForEach-Object {}

I am using Powershell 7.21 on Windows 10 (64 Bit)

1 Answers

I would try a while loop with a counter, see if that has the same issue

$counter = 0
while ($counter -lt 1000000){
write-files
$counter += 1
}
Related