Skip to content

Instantly share code, notes, and snippets.

@mercdev
Last active November 30, 2015 14:19
Show Gist options
  • Save mercdev/98a6908fd144032f8ef6 to your computer and use it in GitHub Desktop.
Save mercdev/98a6908fd144032f8ef6 to your computer and use it in GitHub Desktop.
Queue all enabled builds in TFS via PowerShell
cls
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
$serverName = "http://server.fqdn:8080/tfs"
$teamProject = "project_name"
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDefinitions = $buildServer.QueryBuildDefinitions($teamProject).Name
$buildDefinitions = $buildDefinitions | Sort
foreach($buildDefinitionName in $buildDefinitions)
{
$buildDefinition = $buildserver.GetBuildDefinition($teamProject, $buildDefinitionName)
if ($buildDefinition.Enabled)
{
#if ($buildDefinitionName.Contains("(D") -or $buildDefinitionName.Contains("(T"))
#{
Write-Output "Queuing build -> $buildDefinitionName"
$buildRequest = $buildDefinition.CreateBuildRequest();
$result = $buildserver.QueueBuild($buildRequest)
#}
}
else
{
Write-Output "$buildDefinitionName is disabled, skipping."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment