Closed TRipka07 closed 2 years ago
Can you try the sample here: https://github.com/SpanningCloudApps/SB365-Powershell/blob/master/samples.md#license-an-azure-ad-group We have a new "bulk" endpoint that enables up to 500 users in one request.
Hello,
I've tested with your suggestion. Here is an example of my script:
$userList = [System.Collections.ArrayList]@()
Get-ADGroup -Identity "Spanning Backup Users" | Get-ADGroupMember | ` foreach {$userList.Add($_.UserPrincipalName)}
Enable-SpanningUserList -UserPrincipalNames $userList
Error message I'm receiving:
TerminatingError(Enable-SpanningUserList): "Cannot validate argument on parameter 'UserPrincipalNames'. The number of provided arguments, (1295), exceeds the maximum number of allowed arguments (500). Provide fewer than 500 arguments, and then try the command again." Enable-SpanningUserList : Cannot validate argument on parameter 'UserPrincipalNames'. The number of provided arguments, (1295), exceeds the maximum number of allowed arguments (500). Provide fewer than 500 arguments, and then try the command again.
Can you try grouping them into 500 item lots? Something like this:
#Break List into batches of 500
$group = 500
$i = 0
$userBatch = @()
$results = @()
do {
#Send the batch of Users 500 at a time.
$userBatch = $userList[$i..(($i+= $group) - 1)]
if ($pscmdlet.ShouldProcess("Processing $($userBatch.Count) users", "Enable-SpanningUserList")){
$resultsBatch = Enable-SpanningUserList -AuthInfo $AuthInfo -UserPrincipalNames $userBatch
#Need to join the results
$results += $resultsBatch
}
}
until ($i -gt $userList.count -1)
I've added the batch suggestion and I'm receiving this error.
Enable-SpanningUserList : Cannot validate argument on parameter 'UserPrincipalNames'. The number of provided arguments, (1297), exceeds the maximum number of allowed arguments (500). Provide fewer than 500 arguments, and then try the command again. At C:\Scripts\SpanningBackup\Enable-SpanningUser_v2.ps1:44 char:45
+ CategoryInfo : InvalidData: (:) [Enable-SpanningUserList], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Enable-SpanningUserList
Here is the script with the batch inserted and I may something out of order. Sorry, my powershell skills are not the best.
`#Connect to Spanning Get-SpanningAuthentication -ApiToken $Password -Region US -AdminEmail spanningadmin@domain.com
$userList = [System.Collections.ArrayList]@()
$group = 500
$i = 0
$userBatch = @()
$results = @()
do {
#Send the batch of Users 500 at a time.
$userBatch = $userList[$i..(($i+= $group) - 1)]
if ($pscmdlet.ShouldProcess("Processing $($userBatch.Count) users", "Enable-SpanningUserList")){
$resultsBatch = Enable-SpanningUserList -AuthInfo $AuthInfo -UserPrincipalNames $userBatch
#Need to join the results
$results += $resultsBatch
}
}
until ($i -gt $userList.count -1)
Get-ADGroupMember -Identity "Spanning Backup Users" | Get-ADUser -Properties userPrincipalName | ` foreach {$userList.Add($_.UserPrincipalName)}
Enable-SpanningUserList -UserPrincipalNames $userList `
Are you certain your array has fewer than 500 items? The error indicates that you are still passing too much data.
I am going to write up a sample for this. Closing for now.
Hello,
We have a PowerShell script to license Spanning users who are members of an AD group and are experiencing this error when the script runs.
TerminatingError(Invoke-WebRequest): "Too many requests, please try again later." Invoke-WebRequest : Too many requests, please try again later.
How can we resolve this?
Thanks, Tanner