Reading the result of all releases and deploys in a TFS project

If you need a quick look at the results for all releases and deploys in a TFS project you could make use of the TFS REST API. Following snippet will pull out all the releases for the project and return them in object format.

$TfsUri = http://yourtfs:8080/tfs/yourcollection/'
$TfsProjects = 'yourproject'
$Uri = '{0}{1}/_apis/release/releases' -f $TfsUri, $TfsProject
$Releases = Invoke-RestMethod -Uri $Uri -ContentType application/json -Method Get -UseDefaultCredentials


If you would like to save the result to a file with json-format:

$Releases | ConvertTo-Json –Compress –Depth 10 | Out-File "releases.json"


Or, if you would like to dive deep into all the relesases and verify all the environments and their results you could start by creating an ArrayList for all the Environments:

$ReleaseList = New-Object System.Collections.ArrayList


And then simply iterate all the releases that you read before and add some info from each environment into the ArrayList:

foreach($Release in ($Releases.value)){
  $ReleaseData = Invoke-RestMethod -Uri $Release.url -ContentType application/json -Method Get -UseDefaultCredentials
  $ReleaseData.environments | ForEach-Object {
    $ReleaseList.Add([PSObject]@{ Id=$; Name=$; Environment=$; Status=$_.status; CreatedOn=$_.createdOn }) | Out-Null


If you finally would like to output some readable list you could do something like this:

$TitleRow = "{0,-10} {1,-25} {2,-25} {3,-25} {4,-20}" -f "Id", "Name", "Environment", "CreatedOn", "Status"
Write-Host $TitleRow
$ReleaseList | ForEach-Object {
  $Date = ""
  if(![string]::IsNullOrEmpty($_.CreatedOn)) {
  $DataRow = "{0,-10} {1,-25} {2,-25} {3,-25} {4,-20}" -f $_.Id, $_.Name, $_.Environment, $Date, $_.Status
  if(($_.Status -eq "rejected")-or($_.Status -eq "canceled")) {
    Write-Host $DataRow -ForegroundColor Red
  elseif($_.Status -eq "succeeded") {
    Write-Host $DataRow -ForegroundColor Green
  elseif($_.Status -eq "notStarted") {
    Write-Host $DataRow -ForegroundColor Yellow
    Write-Host $DataRow -ForegroundColor White


Quite simple, this sample is not supposed to be perfect, just a brief description of how to play around with the TFS REST API.

If you want to know more about what you could do with the API, please refer to


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s