PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,223 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The below code is fetching only the first 498 users. How to fetch all the users from Azure DevOps
$organization = ""
$pat = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$apiVersion = "7.1-preview.1"
$users = @()
$url = "https://vssps.dev.azure.com/$organization/_apis/graph/users?api-version=$apiVersion"
$cnt = 1
function Get-Users {
param (
[string]$url,
[hashtable]$headers
)
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
$global:users += $response.value
# Check for continuation token and fetch next page if it exists
if ($response.Headers.'x-ms-continuationtoken') {
$continuationToken = $response.Headers.'x-ms-continuationtoken'
$nextUrl = "https://vssps.dev.azure.com/$organization/_apis/graph/users?api-version=$apiVersion&continuationToken=$continuationToken"
Get-Users -url $nextUrl -headers $headers
}
}
$headers = @{
Authorization = "Basic $base64AuthInfo"
}
Get-Users -url $url -headers $headers
$users | ForEach-Object {
Write-Output $_
Write-Output "User Cnt:" $cnt
$cnt = $cnt + 1
}
Write-host "Total Users - " $users.Count