我正在使用Powershell脚本来自动执行生成代理的过程,该脚本每天都会在设定的时间运行,然后触发回归。我无法使用构建代理名称获取构建代理ID,其中构建代理名称将由用户提供并可以在队列时间设置。
尝试搜索有关此内容的所有内容,但是(在我的上下文中)没有发现任何有用的信息。我在这部分尝试了一些代码。我主要关心的是我是否能够得到计数,但现在还是有价值。检查输出,得到的是我尝试过的代码。
// Getting the list of Agent ID's from the Environmental Variables, splitting & saving in an array.
$agentID = $env:agentIDs -split ","
$URI = "https://URL.com/_apis/distributedtask/pools/xx/agents"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type","application/json")
$headers.Add("Authorization","Bearer $env:SYSTEM_ACCESSTOKEN")
foreach ($element in $agentID)
{
$poolresponse = Invoke-RestMethod -Uri $URI -Method GET -Headers $Headers
echo $poolresponse
// Count is giving the count correct.
echo "count : $($poolresponse.count)"
// However struggling with getting the value.
echo "value : $($poolresponse.value)"
}
实际输出:
count value
----- -----
10 {@{systemCapabilities=; _links=; maxParallelism=1; createdOn=; authorization=; id=133;...}]}
count : 10
value :
任何指导将不胜感激。
答案 0 :(得分:0)
由于它正在返回值中的数组,因此未显示。 我已将其用作: $ poolresponse.value [$ i] 在for循环中,它工作得很好。
尽管感谢@LotPings的帮助。