I would like to see all files that are locked. so far, I've only found to use tf.exe status and look for anything with '!' because they are not reported as "lock, edit" as they are in the UI. Any ideas? thanks.
Asked
Active
Viewed 1.7k times
19
-
Great question, no idea how to do this though... :) – Jeroen Landheer Jun 25 '09 at 03:02
5 Answers
20
If you have the power tools installed, it's a one-liner:
tfstatus . -r -user * | % { $_.pendingchanges } | ? { $_.islock } | select -unique serveritem
If you prefer GUIs to scripts, try TFS Sidekicks.

Richard Berg
- 20,629
- 2
- 66
- 86
-
This looks great. I just installed the power tools the other day but I didnt know it had power shell commandlets. Do you know where I can find documentation on these guys? Also, how to I set it up so powershell can find the dlls? – TheSean Jun 26 '09 at 11:49
-
There should be documentation included in the help file. Also within powershell via the 'help' command. The snap-in and aliases will load automatically if you run the "powershell console" link on the start menu. Or you can copy the settings from the install directory into your $profile. Read my blog for details: http://richardberg.net/blog – Richard Berg Jun 26 '09 at 13:14
-
Couldn't figure out how to do this in TFS Sidekicks. Guess I'll try the power tools. – Patrick Szalapski Oct 27 '10 at 23:40
-
1I had a problem that the TFS Powertools Console didn't know where the TFS server was. The easiest way to tell it is to have the console's shortcut "start in" the root of my local working copy; that way, it automatically detects the TFS server. However, I ran into a problem that the pathname in the shortcut was too long for Windows GUI to handle! I had to uninstall TFS powertools and reinstall them into a shorter path; then, the shortcut GUI would allow me to edit the "start in" directory. I started the console and the above command worked. – Patrick Szalapski Oct 28 '10 at 01:11
6
If you are trying to use TFS Sidekicks, and can't figure out how, it is under Tools, Team Foundation Sidekicks, Status Sidekick. You will need to expand that window, but you will then be able to search for locks for a username.

beenhazed
- 309
- 3
- 3
-
The top two answers are pretty helpful, but this could be interesting. – Austin Henley Oct 06 '12 at 20:57
4
I don't think this is possible using tf.exe or even tfpt.exe (The Power Tool command line). You'll need to look through the pending changesets for changes that are locks. You could do this in powershell using the Power Tool commandlets or you could do it using the following bit of .NET code that exercises the TFS API:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace TfsApiExample
{
class Program
{
static void Main(string[] args)
{
GetLockedFiles("http://tfsserver:8080","$/TeamProject");
}
private static void GetLockedFiles(string serverUrl, string serverPath)
{
TeamFoundationServer tfs = new TeamFoundationServer(serverUrl);
VersionControlServer vcServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
// Search for pending sets for all users in all
// workspaces under the passed path.
PendingSet[] pendingSets = vcServer.QueryPendingSets(
new string[] { serverPath },
RecursionType.Full,
null,
null);
Console.WriteLine(
"Found {0} pending sets under {1}. Searching for Locks...",
pendingSets.Length,
serverPath);
foreach (PendingSet changeset in pendingSets)
{
foreach(PendingChange change in changeset.PendingChanges)
{
if (change.IsLock)
{
// We have a lock, display details about it.
Console.WriteLine(
"{0} : Locked for {1} by {2}",
change.ServerItem,
change.LockLevelName,
changeset.OwnerName);
}
}
}
}
}
}

Martin Woodward
- 11,770
- 31
- 45
3
from your command prompt
>powershell
Then from powershell do:
PS > tf info * -recursive | &{
begin{
$out=@{}
$prefix = "loc"
}
process{
if ($_ -match "Local information"){
if ($out.Count -gt 0) {
[pscustomobject]$out
$out=@{}
$prefix = "loc"
}
} ElseIf ($_ -match "Server information"){
$prefix = "svr"
} else {
$parts = $_.Split(':')
if ($parts.Length -eq 2){
$out.Add($prefix + $parts[0].Trim(), $parts[1].Trim())
}
}
}
end{
if ($out.Count -gt 0) {
[pscustomobject]$out
}
}
} | where {!($_.svrLock -eq 'none')}

Doug Coburn
- 2,485
- 27
- 24
-6
I've found a GUI option.
- Start Visual Studio
- Open file
- Go to source control
- Then workspaces
- Enter your credentials
- Check show remote workspaces
- Remove all unwanted workspaces
That simple :)