Nathan Baulch
Nathan Baulch

Reputation: 20683

How do I list old TFS users that no longer belong to any security groups?

There are lots of examples around that show how to get a list of current TFS users, but how do I get a list of old users that have commit changes in the past but no longer belong to any security groups?

For the record, this is the code I'm using to find all current users:

var gss = tfs.GetService<IGroupSecurityService>();
var members = gss.ReadIdentity(SearchFactor.EveryoneApplicationGroup,
                               null,
                               QueryMembership.Expanded).Members;
return gss.ReadIdentities(SearchFactor.Sid, members, QueryMembership.None)
    .Where(identity => identity != null &&
                       identity.Type == IdentityType.WindowsUser)
    .Select(identity => string.Format(@"{0}\{1}",
                                      identity.Domain,
                                      identity.AccountName));

Upvotes: 2

Views: 372

Answers (2)

pantelif
pantelif

Reputation: 8544

The following snippet should reveal each and every person that has ever committed changes in your TeamCollection repository:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace PeopleWhoHaveCommitedChangesets
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSServer:8080"));
            VersionControlServer vcs = (VersionControlServer) tpc.GetService(typeof (VersionControlServer));
            IEnumerable results = vcs.QueryHistory(@"$/",
                                                    VersionSpec.Latest, 0, RecursionType.Full, null, null, null, int.MaxValue, true, true);
            List<Changeset> changesets = results.Cast<Changeset>().ToList();

            List<string> Users = new List<string>();
            foreach (var changeset in changesets)
            {
                if(!Users.Contains(changeset.Owner))
                {
                    Users.Add(changeset.Owner);
                }
            }
        }
    }
}

Beware that this is a brute force, and, with a lot of changesets, it would take considerable time to execute.

Upvotes: 0

Jason Williams
Jason Williams

Reputation: 57892

I can't offer an exact answer, but hopefully this will help...

You can list all pending changes through the workspaces (i.e. tf.exe workspaces command and equivalent apis). Using the owner of each workspace with uncommitted changes you should then be able to cross-reference against the list of active users you've already got.

Upvotes: 1

Related Questions