title: Get all users under all projects from Azure DevOps
body: <p>I am trying to get all users under couple of project. The case is that under users there are many and I need to to use <strong>continuationToken</strong>. The result is messy because my logic is bad. I cannot figure out how to use the second foreach..</p>
  <pre><code>$outputItems = @()
  
  foreach ($project in $projects) {
      $uriProjectDescriptor = &quot;https://vssps.dev.azure.com/$OrganizationName/_apis/graph/descriptors/$($project.id)?api-version=5.0-preview.1&quot;
      $projectDescriptor = Invoke-RestMethod -Uri $uriProjectDescriptor -Method Get -Headers $AzureDevOpsAuthenicationHeader
      $descriptors = $projectDescriptor.value
  
      foreach ($descriptor in $descriptors) {
      do
      {
          $uriUsers=&quot;https://vssps.dev.azure.com/$OrganizationName/_apis/graph/users?continuationToken=$continuationToken&amp;scopeDescriptor=$($descriptor)&amp;api-version=6.0-preview.1&quot;
          $responseUsers=Invoke-WebRequest -Uri $uriUser -Method Get -ContentType &quot;application/json&quot; -Headers $AzureDevOpsAuthenicationHeader -UseBasicParsing -MaximumRedirection 0
          $continuationToken = $responseUsers.Headers.'x-ms-continuationtoken'
          $userSet = $responseUsers.content | ConvertFrom-Json
          $users += $userSet.value.Count
          $arealList = New-Object -TypeName PSObject -Property @{
              CountUsers = $users.Count
           } | Select-Object &quot;CountUsers&quot;
           $outputItems += $arealList
           $arealList = $null
      }
      while (($continuationToken))
      $ProgressPreference = 'Continue'
      }  
  } $outputItems
  </code></pre>