Home > Back-end >  Run Rest API via PowerShell in order to get the current sprint
Run Rest API via PowerShell in order to get the current sprint

Time:04-02

I am trying to run this script and store in variable and then do $y.value and I get all the sprints for this team. (past,current,future). The goal is to get the current sprint number and store it How can I do that?

$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

The results are:

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

CodePudding user response:

I don't know the api you are using and i don't have access to it. But here is a PowerShell script that can filter the data in your $y variable.

EDIT: Updated Version

$APIUri = "https://tfs.bandit.com/DefaultCollection/Idu Client-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 " "

Dirty short version:

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