0
votes

I'm trying to query TFS to get the change sets that are linked to a set of work items using PowerShell. So far I have been able to do that for a single work item using the following command:

tfpt workitem 928850 /collection:<collection url>

However, I would like to be able to pass in multiple work item IDs at the same time. Does anyone know if this is possible for this command?

I tried pulling multiple work items using a query and the TFPT query command, however it doesn't appear that I can pull linked change sets when using this command.

1
On prem or VSO? If it's an on prem TFS instance I can probably help you with a better way to query your workitems by using actual query statements directly against the database. I used to do some reporting for my old team and had to generate weekly spreadsheets based off our TFS workitems, but I don't think my code works for Visual Studio Online instances of TFS (I don't know, it is untested).TheMadTechnician
It's an on premise TFS instance, however I don't have direct access to the database. Only the web interface and through TFS in Visual Studio.camruny
I should add that I also don't have access to the API, I am only able to use the PowerShell commands through Team Foundation Power Tools (TFPT)camruny

1 Answers

1
votes

If you've got an on prem instance, and can use PowerShell against it, then you should be all set. You're going to need to load the TeamFoundation snapin, and load up a pair of DLLs that should be found in your Visual Studio installation in the path 'Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer'. So, if you have those items you can do this:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell
[System.Reflection.Assembly]::LoadFrom((Resolve-Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll').Path)
[System.Reflection.Assembly]::LoadFrom((Resolve-Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.WorkItemTracking.Client.dll').Path)
$TFS = Get-TfsServer <your TFS URL, something like 'http://MyTFSServer:8080/tfs/MyTeam'>
$WIS = $TFS.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

Once you have a connection to the WorkItemStore you can post queries against it. That is basically the database that stores all your WorkItems for TFS.

$QueryText = "SELECT * FROM WorkItems WHERE [ID] = '928850' OR [ID] = '928851'"
$WorkItems = $WIS.Query($QueryText)

I hope that helps.