Bulk update TFS work items using the web interface

Sometimes there is a much simpler solution to a problem than you originally thought. Or maybe sometimes you just like to do things the hard way (I’m sure most engineers have experience with this 😉 ). In any case, it’s good to know the simple solution, for when you really need it.

Last week I posted about bulk updating TFS work items using Powershell (original post). However, it turns out there is a really simple way to do bulk updates using the TFS Web UI. This can be very helpful when you want to update (one or multiple) field values for many work items at once. I didn’t know about it, so I thought I’d post it here.

Start by creating a query in the TFS Web UI. Here, I created a simple query that selects all Features.

image

Then, select the work items that you want to update. Use Ctrl+Click to select multiple items, use Shift+Click to select a range or just hit Ctrl+a to select them all. Then right-click and select “Edit selected work item(s)…”:

image

You’ll then be presented with a screen where you can select which fields to update and which value to update to. You can also put a comment which will be put in the history field of the selected work items:

image

Once you click “OK”, your items will be updated! If you have a lot of items to update you’ll have a nice “Please wait” screen to stare at… Generally, it won’t take very long though.

image

When finished, your work items will be updated. Don’t forget to click the “Save results” button to save your work items!

image

Note: Using this feature it is possible to set field values which are not allowed (e.g. for the “State” field). When you do this, you’ll notice that your work items will turn red, indicating that they’re not valid:

image

When you do try to save, you’ll be presented with an error message:

image

Happy updating!

Advertisements

Bulk update TFS work items using PowerShell

Today I was faced with a question that persuaded me to try a bit of technology I haven’t used too often yet. I had to set a specific field to a specific value for a large amount of work items. Of course there are multiple ways to achieve that, like using Excel or writing a little application using the TFS API. I decided to brush up on my PowerShell skills and write a script for this purpose.

One of the cool things about PowerShell is that it 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!

So, let’s start by loading the TFS assemblies for working with the TFS Work Item store. These are the assemblies for TFS 2013:

Add-Type -AssemblyName "Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-Type -AssemblyName "Microsoft.TeamFoundation.WorkItemTracking.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

Tip: if you don’t know the Public Key Token, you can find out by using “sn.exe”:

image

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])

From then on, the rest is easy and pretty much similar to using the API as you would from C#. You can find the entire script on my GitHub: TfsBulkUpdateWi.ps1

Happy PowerShell-ing!