Created
March 18, 2021 19:30
-
-
Save vinijmoura/cc0257545ae6ff3fd61bbc91f5ecd8c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param | |
( | |
[string]$PAT, | |
[string]$Organization | |
) | |
$SelfHostedAgentCapabilities = @() | |
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)")) } | |
$UriOrganization = "https://dev.azure.com/$($Organization)/" | |
$UriPools = $UriOrganization + '/_apis/distributedtask/pools?api-version=6.0' | |
$PoolsResult = Invoke-RestMethod -Uri $UriPools -Method get -Headers $AzureDevOpsAuthenicationHeader | |
Foreach ($pool in $PoolsResult.value) | |
{ | |
if ($pool.agentCloudId -ne 1) | |
{ | |
$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)) | |
} | |
} | |
} | |
} | |
} | |
} | |
$SelfHostedAgentCapabilities | ConvertTo-Json | Out-File -FilePath "$home\desktop\SelfHostedAgentCapabilities.json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment