Forum Discussion

VishnuGillela's avatar
VishnuGillela
Copper Contributor
Apr 25, 2021

Export Azure Devops Users and group assignments into csv using az cli

Below script exports all users and their respective group assignments in an azure devops organization into a csv file. 
 
Script needs PATKey and Organization 
 

 

 

[string]$PATKey = "Paste PAT Key Here" ,
[string]$Organization = "Your Organization URL"

$UserGroupsObject = @()

$PATKey | az devops login --org $Organization

az devops configure --defaults organization=$Organization

$Users = az devops user list --top 10000 --org $Organization | ConvertFrom-Json

foreach ($user in $Users.members) {
    $activeUserGroups = az devops security group membership list --id $user.user.principalName --org $Organization --relationship memberof | ConvertFrom-Json
    [array]$groups = ($activeUserGroups | Get-Member -MemberType NoteProperty).Name

    foreach ($group in $groups) {
        $UserGroupsObject += New-Object -TypeName PSObject -Property @{
            principalName = $user.user.principalName
            displayName   = $user.user.displayName
            GroupName     = $activeUserGroups.$group.principalName
        }
    }
}

$UserGroupsObject | Export-CSV -Path "C:\DevopsUsersAndAssignments.csv"

 

 

  • I was trying to export the users using this powershell script, but it is giving me only users who names start with "A" or Is there any limit on the output. I am getting only 168 users as output . Please help me with this, I want to export all users which are around 800.
    • VishnuGillela's avatar
      VishnuGillela
      Copper Contributor
      Thanks rishabhkanwalirk for reporting this issue.

      az devops user list command is having a 'top' argument and I have now increased that to maximum value(10000). With this change upto 10000 users can be listed during execution.

Resources