Creating an undo PowerShell Script for batch updates of Azure DevOps Work Items

Problem

One of my client’s recently had a problem that a large number of Azure DevOps work items had been updated via Excel in error.

They asked if there was a means to undo these edits. Unfortunately, a feature Azure DevOps does not provide.

Solution

So, I wrote a PowerShell script to do it. The script…

  1. Gets a list of work items edited today by a specific user, the one who did the problematic bulk update, using a Work Item Query
  2. Get the last update of each work item and check it was made by the user who did the bulk edit, incase someone manually fixed the problematic update already.
  3. For a limited list of fields, revert the change to the value prior to the last update
  4. Save the updated work item, or if the -whatif flag is set just validate the update against the Azure DevOps instance

For my client, the script worked well enough, reverting over 1000 work items in about 5 minutes. The few work items it could not revert were fixed manually.

The common factor in the work items that it could not revert was that they all had rich text/HTML based descriptions, though so did many that successfully reverted.

I suspect there is an edge case related to the encoding of some character(s) content. However, I have not been able to reproduce the problem as yet on my test rig.

The good news is that if the revert of a work item does fail, the target work item is left unchanged. So allowing either repeated revert attempts with an updated version of the script, or for a manual fix can be done.

You can find the PowerShell script here as a Gist

For the original version of this post see Richard Fennell's personal blog at Creating an undo PowerShell Script for batch updates of Azure DevOps Work Items