How to: List all pools, agent and capabilities of self-hosted agents
2 min readMar 18, 2021
This script list all pools, agents and capabilities on Azure DevOps organization
An original script is available on my GitHub repository. See bellow this script:
Let’s go understand each used command.
- PowerShell script will receive the following parameters:
- $PAT = Personal Access token to connect on Azure DevOps;
- $Organization = Organization URL to list all users and permissions.
2. Get Agent Pools = use this command to list all Agent Pools on Azure DevOps organization.
$UriPools = $UriOrganization + '/_apis/distributedtask/pools?api-version=6.0'
$PoolsResult = Invoke-RestMethod -Uri $UriPools -Method get -Headers $AzureDevOpsAuthenicationHeader
Foreach ($pool in $PoolsResult.value)
{
Write-Host $pool.name
}
3. Get Agents = use this command to list all agents and capabilities on the respective pool.
$uriAgents = $UriOrganization + "_apis/distributedtask/pools/$($pool.Id)/agents?api-version=6.0" $AgentsResults = Invoke-RestMethod -Uri $uriAgents -Method get -Headers $AzureDevOpsAuthenicationHeader Foreach ($agent in $AgentsResults.value)
{
$uriSelfHostedAgentCapabilities = $UriOrganization + "_apis/distributedtask/pools/$($pool.Id)/agents/$($agent.Id)?includeCapabilities=true&api-version=6.0"
$SelfHostedAgentCapabilitiesResult = Invoke-RestMethod -Uri $uriSelfHostedAgentCapabilities -Method get -Headers $AzureDevOpsAuthenicationHeader
Foreach ($shac in $SelfHostedAgentCapabilitiesResult)
{
$Capabilities = $shac.systemCapabilities | Get-Member | where {$_.MemberType -eq 'NoteProperty'}
Foreach ($cap in $Capabilities)
{
$SelfHostedAgentCapabilities += New-Object -TypeName PSObject -Property @{
PoolName=$pool.name
AgentName=$agent.name
CapabilityName=$cap.Name
CapabilityValue=$($shac.systemCapabilities.$($cap.Name))
}
}
}
}
4. After executing the script on PowerShell, will be generated a JSON file that lists all pools, agents, and your respective capabilities.
5. After creating JSON, I connected it on Power BI, as shown below:
- Pools (1): filter a respective poll to agents;
- Agents (2): list respective capabilities to a specific agent;
- Capabilities (3): list all capabilities on a respective agent.