<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00008wsZ0qCAEOkta Classic EngineAPI Access ManagementAnswered2023-03-17T18:43:25.000Z2023-03-16T19:47:07.000Z2023-03-17T18:43:25.000Z

SebastienU.52034 (Customer) asked a question.

Powershell - API Users - Limit 200

We want to create a script on powershell to add in a okta group all users have second factor enrolled

We arrived to list the first 200 users but not all.

 

We have a problem with '@odata.nextLink' that return null value.

 

Can you help us please ?

Thanks

 

---------------------------------

 

$apiKey = "AAAAAAAAAAAAA"

$orgUrl = "https://yyyyyy.okta.com"

$groupId = "xxxxxxxxxxxxxxx"

$headers = @{

  Authorization = "SSWS $apiKey"

  ContentType = "application/json"

}

$url = "$orgUrl/api/v1/users?filter=status eq " + [char]34 + "ACTIVE" + [char]34

$results = @()

do {

  $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get

  write-host $response.Count -BackgroundColor Yellow

  $results += $response

  $url = $response.'@odata.nextLink'

} while ($url -ne $null)

 

foreach ($user in $response) {

  Write-Host "Processing user:" $user.profile.login  

  $userId = $user.id

  $url2 = "$orgUrl/api/v1/users/$userId/factors"

  $response2 = Invoke-RestMethod -Uri $url2 -Method Get -Headers $headers

  foreach ($factor in $response2) {

    if ($factor.factorType -ne "token:software:totp") {

      Write-Host "User:" $user.profile.login

      $url3 = "$orgUrl/api/v1/groups/$groupId/users/$userId"

     *Invoke-RestMethod -Uri $url3 -Method Put -Headers $headers

      Write-Host "User:" $user.profile.login "has been added to group."

    }

  }

}

 


This question is closed.
Loading
Powershell - API Users - Limit 200