是否可以获得所有已安装的可用构建代理的列表?
我正在使用TFS 2018,并希望获取包含沿其托管计算机名称安装的所有构建代理的excel。如果可能,怎么办?
答案 0 :(得分:2)
您可以使用下面的Powershell脚本获取所有代理池中的代理列表并导出到excel(可以在excel中打开的*.csv
文件):
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
}
答案 1 :(得分:0)
您可以创建Powershell脚本(使用Invoke-RestMethod
)来使用REST Api并获取代理。
例如:
http://TFS-SERVER:8080/tfs/_apis/distributedtask/pools/1/agents?includeCapabilities=false&includeAssignedRequest=true
在上面的api中,您将获得池1中的所有代理,您可以遍历所有池id并获取所有代理,然后将数据导出到excel。
有关Powershell here的Invoke-RestMethod
的更多信息。