PowerShell Script for User Creation Stops After 100 Users

ares 206 Reputation points
2025-09-30T22:23:55.89+00:00

A PowerShell script is being used to create users, but it stops working after creating 100 users. Is there a known limitation or block on user creation via PowerShell that could cause this issue?

Thanks

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Burlachenko 18,310 Reputation points Volunteer Moderator
    2025-10-01T09:01:31.43+00:00

    ares hi,

    when you make too many api calls too quickly, entra id, formerly azure ad, will start to throttle your requests and return errors. the exact limit for user creation is not publicly documented because it is dynamic, but hitting a wall around 100 users is very common for a fast running script.

    your script is not broken, it is just going too fast for the service to handle.

    here is how you can fix it. you need to add a delay between each user creation command in your powershell loop. this is called throttling or pacing your script.

    inside your foreach loop, right after the new-azaduser command, add a start-sleep command. a delay of 1 or 2 seconds is usually enough to stay under the rate limit.

    foreach ($user in $userlist) { new-azaduser ...all your parameters... start-sleep -seconds 2 }

    this simple change will make your script take longer to run, but it will run reliably to the end without being blocked.

    another thing to look into is using the -batch parameter if the cmdlet supports it, but for user creation, the sleep method is the most straightforward.

    this is not just an azure thing. any cloud api, like google workspace or aws, has similar rate limits. pacing your scripts is a universal best practice for cloud automation.

    so, your script is fine, it just needs a small start-sleep command inside the loop to slow it down and be a good citizen to the api.

    rgds,

    Alex

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.