Error when adding many office users with powershell

marialozy 35 Reputation points
2023-03-30T12:45:39.53+00:00
I'm trying to create a user (office365) using powershell a lot

Import-CSV –Path C:\PODCAST\file.csv |ForEach-Object { New-MsolUser -UserPrincipalName $_.username -DisplayName $_.displayname –Password $_.Password -UsageLocation $_.Location -LicenseAssignment $_. license -ForceChangePassword $false }

But after a while (only 100+ users too) an error will appear

New-MsolUser : You have exceeded the maximum number of allowable transactions. Please try again later.
At line:1 char:53
+ ... ch-Object { New-MsolUser -UserPrincipalName $_.username -DisplayName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
     + CategoryInfo : OperationStopped: (:) [New-MsolUser], MicrosoftOnlineException
     + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.ThrottlingException,Microsoft.Online.Administration.Automation.NewUser


Even though 2 days ago it still could.
Microsoft Office Online Server
Microsoft Office Online Server
Microsoft on-premises server product that runs Office Online. Previously known as Office Web Apps Server.
672 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,627 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Amit Singh 5,071 Reputation points
    2023-03-31T05:41:21.8566667+00:00

    You can only add up to 50 maximum number of email accounts, and if you wish to add more, you need to register your domain to Office 365 to have the desired members under your domain.


  2. marialozy 35 Reputation points
    2023-03-31T08:50:48.6166667+00:00

    contoh-1

    contoh 2

    New-MsolUser : You have exceeded the maximum number of allowable transactions.

    Previously if too many powershell tabs (will error like that)

    It's just one tab only error.


  3. jati bad boy 0 Reputation points
    2023-04-04T17:33:30.6266667+00:00

    ..........

    0 comments No comments

  4. Stella Trice 0 Reputation points
    2023-05-03T05:22:54.08+00:00

    i have a same problem after microsft update

    0 comments No comments

  5. Rich Matheisen 47,596 Reputation points
    2023-07-21T15:48:41.9+00:00

    I haven't tested this, but it should handle the throttling problem. You can adjust the size of each batch and the pause between batches. I don't have access to M365 to come up with any good values for either of those.

    $BatchSize = 100
    $changes = 0
    $DoIt = $true
    $pause = 5
    Import-CSV -Path C:\PODCAST\4.csv |
        ForEach-Object {
            $props = @{
                UserPrincipalName = $_.username
                DisplayName = $_.displayname
                Password = $_.Password
                UsageLocation = $_.Location
                LicenseAssignment = $_.license
                ForceChangePassword = $false
                ErrorAction = "STOP"           
            }
            $changes++
            if ($changes -ge $BatchSize){
                Start-Sleep -Seconds $pause
                $changes = 0
            }
            $DoIt = $true
            Do{    
                Try{
                    New-MsolUser @props
                    $DoIt = $false          # no error, so don't retry
                }
                Catch{
                    If ($_.FullyQualifiedErrorId -like "*Microsoft.Online.Administration.Automation.ThrottlingException*"){
                        Start-Sleep -Seconds $pause
                    }
                    else{
                        # handle error here, or just report it and skip current user
                        $DoIt = $false  # stop any retries
                    }
                }
            } While ($Doit)
        }
    
    0 comments No comments

Your answer

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