Today I needed to use the TFS API to get the last successful green build info from TFS so I thought whilst I'm still learning PowerShell I'll give it a go in that. Anyway here's what I came up with, I could have condensed the lines but whilst I was debugging in PowerShellGUI (which is REALLY good for PowerShell development!) I wanted to see what each method returned.
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
$tfsCollectionUrl = "http://SERVERNAME:8080/tfs/COLLECTION"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDetail = $buildServer.QueryBuilds("TEAM_PROJECT", "BUILD_DEFINITION_NAME") | where { $_.BuildDefinition.LastGoodBuildUri -eq $_.Uri } #| select BuildNumber
$buildDetail will contain an IBuildDetail object as described here: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddetail.aspx
acd55f62-bb6a-490e-9f41-0de850cc83cf|1|5.0