Deleting the TFS workspace for a missing account fails (TF50605)

Having decommissioned a few legacy AD DS domains over the last year or so we’ve had a few references in TFS to missing accounts. When attempting to delete the workspace you get the following error:

TF50605: There was an error looking up the SID for OLD-DOMAIN\CCNETNIGHTLYBUILD.

In order to delete the workspace, we need to remap it to a valid user account. Here’s the process to do just that.

Firstly, we should list the workspaces on this computer we’re having problems with (in this case, BUILDSERVER01).

C:\>tf workspaces /owner:* /server:http://tfs-server:8080 | findstr BUILDSERVER01
Workspace		Owner				Computer	Comment
----------------------- ------------------------------- --------------- -------------------------------
BUILDSERVER01		saCCNetNightly			BUILDSERVER01	Temporary CruiseControl.NET Wo

We may as well attempt to delete the workspace, though the process is likely to fail as it wont be able to resolve the SID if the domain is no longer available.

C:\>tf workspace /delete /server:http://tfs-server:8080 BUILDSERVER01;OLD-DOMAIN\CCNETNIGHTLYBUILD
TF50605: There was an error looking up the SID for OLD-DOMAI\CCNETNIGHTLYBUILD.

At this point, we need to open up the TfsVersionControl table and manually point the workspaces to a valid identity. The first stage is to identify the ID of the missing account:

SELECT IdentityId FROM tfsVersionControl.tbl_Identity WHERE (DisplayName LIKE 'OLD-DOMAIN\CCNETNIGHTLYBUILD')

Now that we have the ID, we can locate the workspaces the owner has on the server we’re having problems with.

SELECT WorkspaceId, OwnerId, WorkspaceName FROM tfsVersionControl.tbl_Workspace WHERE (OwnerId = 311) AND (Computer = 'BUILDSERVER01')

We should now update the tfsVersionControl.tbl_Workspace table with a valid IdentityId from the tfsVersionControl.tbl_Identity table. Once that’s done, try the delete command again:

C:\>tf workspace /delete /server:http://tfs-server:8080 "BUILDSERVER01;Dave Hope"
A deleted workspace cannot be recovered.
Workspace 'BUILDSERVER01;Dave Hope' on server 'http://tfs-server:8080' has 0 pending change(s).
Are you sure you want to delete the workspace? (Yes/No) Yes

And hey presto, the workspace is gone.