How to: Extract Organization Level Permissions from the respective user in Azure DevOps

This script and report extract Organization Level Permissions from the user. Before that, it’s necessary to get all groups to which that user belongs.

DISCLAIMER: Due to the number of records generated by this report, one mandatory filter was placed: the name of the user. This report was based on the ALM Rangers project Extracting effective permissions from TFS. Within Azure DevOps, click on Organization Settings, after clicking in Permissions, and select a respective group.

An original script is available on my GitHub repository. See below this script:

Let’s go understand each command used.

  1. PowerShell script will receive the following parameters:
  • $PAT = Personal Access token to connect on Azure DevOps;
  • $Organization = Organization URL to list permissions on Organization Level;
  • mailAdress = e-mail from respective user to which permissions will be extracted;
  • $Connstr = connection string to Azure SQL Database to store the report information. To create this report, it’s necessary to create previously a Azure SQL Server and Database and run a script below:

2. az devops user list = use this command to list all users on Azure DevOps organization. After that, it’s necessary to filter a respective user that was received by parameter.

$allUsers = az devops user list 
--org $Organization | ConvertFrom-Json

3. az devops security group membership list = use this command to list all groups that user (received by parameter) is contained in.

$activeUserGroups = az devops security group membership list 
--id $allUsers.principalName
--org $Organization
--relationship memberof | ConvertFrom-Json

4. In Azure DevOps, when working with permissions, it’s necessary to understand SecurityNameSpaces. Basically, each namespace represents the respective set of permissions on Azure DevOps (Git, Area Path, Project Level, Iterations, Builds, Releases, etc.). To this example, to represent permission on Organization Level will be used namespaces AuditLog, Collection, BuildAdministration, Project, VersionControlPrivileges, Process, and Server, which is represented by the constants below:

$SecurityNameSpaceIds = @(    [pscustomobject]@{

5. Token = At the moment that we extract any kind of permission on Azure DevOps, it’s necessary to work with tokens. For each type of permission, there is a specific rule to produce that token. For each namespace, there is the specific rule:

  • AuditLog
'AuditLog' { $Token = "/AllPermissions" }
  • Collection
'Collection' { $Token = "NAMESPACE" }
  • BuildAdministration
'BuildAdministration' { $Token = "BuildPrivileges" }
  • Project
'Project' { $Token = "`$PROJECT" }
  • VersionControlPrivileges
'VersionControlPrivileges' { $Token = "Global"}
  • Process
'Process' { $Token = "`$PROCESS" }
  • Server
'Server' { $Token = "FrameworkGlobalSecurity" }

6. More details about other tokens can be found in the links below:

7. az devops security permission show = Show details of permissions available in each namespace

$organizationCommands = az devops security permission show 
--id $snsi.SecurityIdSpace
--subject $activeUserGroups.$aug.descriptor
--token $Token
--org $Organization | ConvertFrom-Json

8. After extract all permissions, this information is stored in a table in Azure SQL.

9. After insert information into a table, I connected this database on Power BI:

  • Azure DevOps Groups (1) = Filter Azure DevOps Groups to which the user belongs;
  • Azure DevOps Groups (2) = list all Azure DevOps groups to which the user belongs;
  • Permission Group Type (3) = List of Permission Group Type (General, Service Account, Boards, Repos, Pipelines, Test Plans, Auditing, Policies);
  • Command (4) = List of commands available to Organization Level;
  • Permission (5) = Permission type (Allow, Deny, Not set, etc.).

DevOps Consultant at N3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store