I'm newbbie on Azure DEVOPS CLI, and I need assign an specific user to all projects in my organization using AZURE DEVOPS CLI. The total of projects of the organization it´s about 25 projects.
Greetings.
To add a user to all projects in your organization using Azure DevOps CLI, you can refer to the followings.
Prerequisites
Steps
Sample
The following PowerShell scripts add the user to the Readers group of all projects. Replace the value of userEmail
, organization
, AZURE_DEVOPS_EXT_PAT
and displayName
based on your requirement.
# Define user and organization details
$userEmail = "{The user email}"
$organization = "{Org name}"
# Define Personal Access Token (PAT) as environment variable for authentication
$env:AZURE_DEVOPS_EXT_PAT = '{PAT}'
# Get list of all projects in the organization
$projects = az devops project list --organization https://dev.azure.com/$organization | ConvertFrom-Json
# Loop through each project
foreach ($project in $projects.value) {
$projectId = $project.id
# Get the Readers group descriptor for the project
$groupid = az devops security group list --organization https://dev.azure.com/$organization --project $projectId --query "graphGroups[?displayName=='Readers'].descriptor| [0]"
# Add the user to the Readers group
az devops security group membership add --group-id $groupid --member-id $userEmail --org https://dev.azure.com/$organization
}