How to: Deployment Groups and Target Machines Capabilities Mapping on Azure DevOps

Vinicius Moura
2 min readSep 30, 2022

--

This script and report extract all Deployment Groups and Target Machines Capabilities within the Azure DevOps organization

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 all Deployment Groups and respective Target Machines;
  • $Connstr = connection string to Azure SQL Database that stores 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. Projects List = uses this REST API to list all Team Projects on Azure DevOps organization

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)")) }$UriOrganization = "https://dev.azure.com/$($Organization)/"$UriOrgRelease = "https://vsrm.dev.azure.com/$($Organization)/"$uriProject = $UriOrganization + "_apis/projects?`$top=500"$ProjectsResult = Invoke-RestMethod -Uri $uriProject -Method get -Headers $AzureDevOpsAuthenicationHeaderforeach ($teamproject in $ProjectsResult.value)
{
Write-Host $project.name
}

3. Deploymentgroups List = uses this REST API to list all Deployment Groups on each Project

$uriDeploymentGroup = $UriOrganization + "$($teamproject.name)/_apis/distributedtask/deploymentgroups"    $DeploymentGroupResult = Invoke-RestMethod -Uri $uriDeploymentGroup -Method Get -Headers $AzureDevOpsAuthenicationHeader    foreach ($deploymentGroup in $DeploymentGroupResult.value)
{
Write-Host $deploymentGroup.name
}

4. Deploymentgroups Get = use this REST API to get all Target Machines on each Deployment Group

$uriDeploymentGroupMachines = $UriOrganization + "$($teamproject.name)/_apis/distributedtask/deploymentgroups/$($deploymentGroup.id)"            $DeploymentGroupMachinesResult = Invoke-RestMethod -Uri $uriDeploymentGroupMachines -Method Get -Headers $AzureDevOpsAuthenicationHeader            foreach ($dgMachine in $DeploymentGroupMachinesResult.machines)            {
Write-Host $dgMachine.agent.name
}

5. Targets Get = use this REST API to get all Capabilities on each Target Machines

$uriMachineCapabilities = $UriOrganization + "$($teamproject.name)/_apis/distributedtask/deploymentgroups/$($deploymentGroup.Id)/targets/$($dgMachine.agent.id)?`$expand=capabilities&api-version=6.0-preview.1"                $MachineCapabilitiesResult = Invoke-RestMethod -Uri $uriMachineCapabilities -Method Get -Headers $AzureDevOpsAuthenicationHeader                $machCap = $MachineCapabilitiesResult.agent.systemCapabilities | Get-Member | where {$_.MemberType -eq 'NoteProperty'}                Foreach ($cap in $machCap)
{
Write-Host $cap.Name
Write-Host $MachineCapabilitiesResult.agent.systemCapabilities.$($cap.Name)
}

6. After extracting all Deployments Groups and Target Machines, this information is stored in a table in Azure SQL.

6. After inserting information into a table, I connected this database on Power BI:

  • Team Project (1) = Filter report using Team Project field;
  • Deployment Group Name (2) = Filter report using Deployment Group Name field;
  • Machine Name (3) = Filter report using Machine Name field;
  • Information (4) = List all information about Projects, Deployment Groups, Target Machines, and Capabilities.

--

--