简体   繁体   中英

Get list of all installed Build Agents in TFS 2018

Is it possible to get a list of all Available Build Agents Installed?

I am using TFS 2018 and want to fetch the excel containing all build agents installed along their hosted Machine names. If it is possible, how?

You can use below Powershell script to get the list of agents in all agent pools and export to excel (a *.csv file which can be opened in excel):

Param(
   [string]$collectionurl = "http://server:8080/tfs",
   [string]$user = "username",
   [string]$token = "password",
   [string]$path = "D:\temp" # Export the agent list (*.csv file) to this path

)

$filename = (Get-Date).ToString("yyyyMMdd-HHmmss") + "-" + "AgentList.csv"

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

#Get pools 
$poolsUrl = "$collectionurl/_apis/distributedtask/pools"            
$poolresponse = Invoke-RestMethod -Uri $poolsUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$pools = $poolresponse.value

foreach ($pool in $pools )
{
#Get agent list from pool
$baseUrl = "$collectionurl/_apis/distributedtask/pools/$($pool.id)/agents?includeCapabilities=true&includeAssignedRequest=true"         
$agentresponse = Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$agents = $agentresponse.value

$agentlist = @()

   foreach ($agent in $agents)
   {

    $customObject = new-object PSObject -property @{
          "PoolName" = $pool.name
          "Agent.Name" = $agent.systemCapabilities.'Agent.Name'
          "Agent.Version" = $agent.systemCapabilities.'Agent.Version'
          "Agent.ComputerName" = $agent.systemCapabilities.'Agent.ComputerName'
        } 

    $agentlist += $customObject
   }

   $agentlist | Select `
                PoolName,
                Agent.Name,
                Agent.Version, 
                Agent.ComputerName |export-csv -Path $path\$filename -NoTypeInformation -Append

}

在此处输入图片说明

You can create Powershell script (with Invoke-RestMethod ) to use REST Api and get the agents.

For example:

http://TFS-SERVER:8080/tfs/_apis/distributedtask/pools/1/agents?includeCapabilities=false&includeAssignedRequest=true

In the api above you will get all the agents in pool 1, you can iterate over all the pools id's and get the all agents, after that export the data to excel.

More information about Invoke-RestMethod of Powershell here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM