TFS: Import group members from CSV text file

August 18, 2006 at 4:11 am | In Team Foundation Server |

As part of our migration process away from Visual SourceSafe we have to ensure that the same permissions are applied in TFS Source Control. My last post was VssPermissions.exe that dumps the current permissions to a CSV file.

The logical next step is something that is able to process a CSV file and add the users to the specified TFS security groups.

TfsGroupMemberImport.exe 

Processes a CSV text file with two columns: user,groupname and places them in to TFS groups. The groups must already exist in TFS.

Usage

TfsGroupMemberImport [server] [input filename] [user domain] [team project]

Example

TfsGroupMemberImport http://server:8080/ groups.txt mydomain MyTeamProject

Input Format

Username without the leading domain\, and TFS group name without the team project. No quotes needed. For example:

username,tfs group name
granth,contributors
jsmith,readers

Discussion

This tool is quite specific for my own requirements, but there’s nothing stopping you modifying it to fit yours. You could also achieve the same result by creating something that leverages the tfssecurity.exe command line utility.

  • tfssecurity /g+ “n:[teamproject]\group name” “n:domain\username”

TFS API Code

We make use of the IGroupSecurityService from the Microsoft.TeamFoundation.* object model. The key methods are:

  • TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(serverUrl);
  • IGroupSecurityService groupSecurityService = (IGroupSecurityService) tfs.GetService(typeof (IGroupSecurityService));
  • groupSecurityService.ReadIdentity(SearchFactor.AccountName, accountName, QueryMembership.None).Sid
  • groupSecurityService.AddMemberToApplicationGroup(groupSid, userSid);

Download

You can download the code from the TFS GroupMemberImport project on project distributor. Direct download source and binary here.

Feedback

Please let me know if you find this useful by leaving a comment. All feedback welcome.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.