Unlocking files in TFS

If you ever come across a situation where someone has left the company or go for holiday with files locked, you can follow these steps to remove an existing lock.

The user had not unlocked all files before having over their old machine and was receiving the message “TFS10151: Cannot lock item”.

This is the message the user received when trying to edit a previously locked file.

TFS 2007
To unlock the file, run the following command:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>tf undo /workspace:workstation_name;DOMAIN\user $/Project/path

To get a list of workspaces run this:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>tf workspaces /owner:DOMAIN\user /computer:*

TFS 2010
To unlock the file, run the following command:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE>tf undo /workspace:workstation_name;username /server:http://website.com:8080/tfs/Collection_Name
$/Project/path

If the user has left the company, you may want to delete his workspace. Deleting the workspace also removes the lock on the files, but deleted workspace cannot be recovered.

To delete the workspace, run the following command:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE>tf workspace /delete /server:http://website.com:8080/tfs/Collection_Name workstation_name;domain\username