Search code examples
tfstfs-workitem

Update the same field in multiple work items through TFS API or powershell script


I know we could bulk update TFS work items with Excel.

However, this time I want to integrate this in my build process. Do it either with TFS API or power shell script. We are working on TFS2017/VS2017

I look forward to any suggestions from your guys.


Solution

  • You could do this through a powershell script based on TFS client API.

    PowerShell lets you load any .Net assembly by using the Add-Type cmdlet.

    You can then use the classes defined in that assembly inside your PowerShell session. This opens up a wide range of possibilities, one of them being that you can use the TFS API from PowerShell.

    • Microsoft.TeamFoundation.Client
    • Microsoft.TeamFoundation.WorkItemTracking.Client

    After the TFS assemblies have been loaded, we can get a reference to the TPC:

    $tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUri)
    

    And then the $tfs object can be used to access the required services (the work item store in this case):

    $workItemStore = $tfs.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
    

    For the other things and more detail, you could find the entire script on KeesV's GitHub: TfsBulkUpdateWi.ps1

    Another blog for your reference: How to batch update multiple work items in TFS by PowerShell