Deleting a TFS workspace from the command line

Today I had need to explicitly remove a TFS 2015 workspace. I was troubleshooting a build and wanted to completely remove any workspace the build service might be using.

I did this from a new TFS 2015 Build Agent machine (non-XAML) that had VS2015 installed as well. The process I used to do this was as follows.

  1. Open a developer command prompt

  2. Get a list of all workspaces (you can refine further if needed)

tf workspaces /server:http://{TFSServername}:8080/tfs/{CollectionName} /owner:*

This will return a list of all workspaces including the Owner of the workspace. Find the name of the workspace you want to delete and also pay attention to the owner name.

  1. Use the following command to delete the specific workspace. (NOTE: The command above uses “workspaces” while this command uses “workspace” not the plural form)

tf workspace /server:http://{TFSServername}:8080/tfs/{CollectionName} /delete “{workspacename};{owner}”

In my case, I was looking for a workspace used by the new TFS 2015 Build Agent. This meant I could specify the workspace owner as “Project Collection Build Service” which was the scope I was using. This reduced the list of workspaces significantly which made it easy to find the workspaces I wanted to delete.

This was the exact command line I used as an example.

tf workspace /server:http://TFS:8080/tfs/DefaultCollection
/delete “ws_1_2;Project Collection Build Service”

If I had been scoping the build to just the Team Project, I would have used the “Project Build Service” instead.