Ken-F
Ken-F

Reputation: 152

export complete TFS work item incl. history with PowerShell

I am working for a customer who is running a Dynamics AX project and is using TFS. I do have access to TFS and am able to check all the different work items - however, what I am missing is an overview to build metrics as the only way to get data into a table (Excel) does not allow me to get the history of a work item.

I am hence wondering how I could do this using PowerShell. I am completely new to this, accordingly step-by-step guidance would be highly appreciated.

Upvotes: 0

Views: 542

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41575

You can use TFS Rest API.

For example:

$serverUrl = "http://tfsServer:8080/tfs/Collection"
$workItemId = "1"

#Get the Work Item 
$workItem = Invoke-RestMethod -Uri "$($serverUrl)/_apis/wit/workitems/$($workItemId)?api-version=3.0" -UseDefaultCredentials -Method Get

#Print the revisions number
Write-Host $workItem.rev

#Get the specific revision details
$revision = Invoke-RestMethod -Uri "$($serverUrl)/_apis/wit/workitems/$($workItemId)/revisions/2?api-version=3.0" -UseDefaultCredentials -Method Get

#Print the Work Item details in the specific revision
Write-Host $revision.fields

Upvotes: 1

Related Questions