运行 通过 PowerShell 休息 API 以获得当前的 sprint

Run Rest API via PowerShell in order to get the current sprint

我正在尝试 运行 此脚本并将其存储在变量中,然后执行 $y.value 并获得该团队的所有冲刺。 (过去,现在,未来)。目标是获取当前的 sprint 编号并存储 我该怎么做?

$y = Invoke-RestMethod -UseDefaultCredentials -Uri "https://tfs.bandit.com/DefaultCollection/Idu Client-Server/SRE/_apis/work/teamsettings/iterations?$timeframe=current&api-version=5.0"
$y.value

结果是:

id         : 760c925c-db3c-4d81-be19-485027a09d93
name       : Sprint 72
path       : Idu Client-Server\Sprints\Sprint 72
attributes : @{startDate=2022-02-27T00:00:00Z; finishDate=2022-03-17T00:00:00Z; timeFrame=past}
url        : https://tfs.bandit.com/DefaultCollection/17944823-be9c-40ea-b970-2a2989d6ddd4/15a27310-2250-4786-a935-946b0dccf206/_apis/work/teamsettings/iterations/760c925c-db3c-4d81-be19-485027a09d93

id         : 8a9987cb-fb2d-4de2-8db8-5303cc7748e5
name       : Sprint 73
path       : Idu Client-Server\Sprints\Sprint 73
attributes : @{startDate=2022-03-20T00:00:00Z; finishDate=2022-04-07T00:00:00Z; timeFrame=current}
url        : https://tfs.bandit.com/DefaultCollection/17944823-be9c-40ea-b970-2a2989d6ddd4/15a27310-2250-4786-a935-946b0dccf206/_apis/work/teamsettings/iterations/8a9987cb-fb2d-4de2-8db8-5303cc7748e5

id         : ab3c4a30-8141-4923-82cf-067b5d0aaed3
name       : Sprint 74
path       : Idu Client-Server\Sprints\Sprint 74
attributes : @{startDate=2022-04-10T00:00:00Z; finishDate=2022-04-28T00:00:00Z; timeFrame=future}
url        : https://tfs.bandit.com/DefaultCollection/17944823-be9c-40ea-b970-2a2989d6ddd4/15a27310-2250-4786-a935-946b0dccf206/_apis/work/teamsettings/iterations/ab3c4a30-8141-4923-82cf-067b5d0aaed3

我不知道您使用的 api 并且我无权访问它。但这里有一个 PowerShell 脚本,可以过滤 $y 变量中的数据。

编辑:更新版本

$APIUri = "https://tfs.bandit.com/DefaultCollection/Idu%20Client-Server/SRE/_apis/work/teamsettings/iterations?timeframe=current&api-version=5.0"
$APIData = (Invoke-RestMethod -UseDefaultCredentials -Uri $APIUri).Value
$CurrentAPIObject = $APIData |where {($_.attributes).timeFrame -eq "current"}
$null, [int]$CurrentSprintInteger = $CurrentAPIObject.Name -split " "

脏短版:

[int](($y.value |where {($_.attributes).timeFrame -eq "current"}).Name -split " ")[-1]