Is there a way, either via a query or programmatically, to identify all TFS Changesets that are NOT linked to a Work Item?
3 Answers
Using the TFS PowerToy's PowerShell module:
From whatever folder in your workspace you're interested in:
Get-TfsItemHistory . -Recurse | Where-Object { $_.WorkItems.Length -eq 0 }
This will get the history for the current folder and all subfolders, and then filter for empty workitem lists.

- 106,783
- 21
- 203
- 265
-
See the answer [here](http://stackoverflow.com/questions/1050689/how-do-i-set-up-tfs-powershell-snapin) if (like me) you don't know how to get the powershell addin working. – DeanOC May 02 '13 at 02:59
I don't know about Richard's Answer but the accepted answer took almost 2 minutes to run from the root of my team project collection. This runs in 10 seconds if you are looking for a specific user, 47 seconds if you aren't.
service.QueryHistory("$/TeamProject/", VersionSpec.Latest,0, RecursionType.Full,userName,null,null, Int32.MaxValue,true,false)
.Cast<Changeset>()
.Where(cs=>cs.AssociatedWorkItems.Length==0)
if you aren't looking for a specific user just set userName
to null
Sure, you can use the TFS API to do this very easily.
public static void GetAllChangesetsWithNoWorkItems()
{
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs2010/tfs/default"));
var service = tfs.GetService<VersionControlServer>();
var histories = service.GetBranchHistory(new ItemSpec[] { new ItemSpec(@"$/ProjectName/MAIN/BUILD", RecursionType.OneLevel) }, VersionSpec.Latest);
foreach (BranchHistoryTreeItem history in histories[0])
{
var change = service.GetChangeset(history.Relative.BranchToItem.ChangesetId, true, true);
if(change.WorkItems.ToList().Count == 0)
{
Debug.Write(String.Format("Work Item Missing for Changeset {0}", change.ChangesetId));
}
}
}
You can read this blog post on how to connect to TFS API Programmatically http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx

- 160,644
- 26
- 247
- 397

- 4,692
- 4
- 30
- 40