Bringing you news, technical articles, and other useful content about Visual Studio ALM and Team Foundation Server
More videos »
Quick Response samples provide information directly from Visual Studio ALM Rangers working with the Microsoft Visual Studio Product Group, in response to feature gaps to supplement the product and knowledge base information.
The Visual Studio and Team Foundation Server VM Factory automation team, working on the Visual Studio Readiness “Gig” Hands-on Lab (HOL) prerequisite setup automation, required a command line utility, such as TFSSecurity.exe , to add Teams and Team members to a Team Project. Investigations highlighted that in Visual Studio Team Foundation Server 2012 RC, a command line utility with the feature to manage teams and their members does not exist. A feature gap !
Team Foundation Server has extensive support for Teams and Team membership management through the object model. You can build your own Teams administrative command line utility, using the ALM Rangers oob_TfsTeams sample solution, which you can download from Supporting Guidance and Whitepapers, in the Quick Response download package.
The sample is based on using the Team service which an extension on top of the Identity Management Service (IMS) in TFS. Refer to Team Foundation Server Architecture for more information on these services.
To use the sample, proceed as follows:
Sample extract, TeamWrapper.cs:
1: // Copyright © Microsoft Corporation. All Rights Reserved.
2: // This code released under the terms of the
3: // Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
4: // This is sample code only, do not use in production environments
5: namespace Microsoft.ALMRangers.TfsTeams
6: {
7: using System;
8: using System.Collections.Generic;
9: using System.Linq;
10: using Microsoft.TeamFoundation.Client;
11: using Microsoft.TeamFoundation.Framework.Client;
12: using Microsoft.TeamFoundation.Framework.Common;
13: using Microsoft.TeamFoundation.Server;
14: using System.Diagnostics;
15:
16: internal class TeamWrapper : IDisposable
17: {
18: private readonly TfsTeamProjectCollection teamProjectCollection;
19: private readonly TfsTeamService teamService;
20: private readonly ProjectInfo projectInfo;
21: private readonly IIdentityManagementService identityManagementService;
22:
23: public TeamWrapper(Uri collectionUri, string teamProjectName)
24: {
25: this.teamProjectCollection = new TfsTeamProjectCollection(collectionUri);
26: this.teamService = this.teamProjectCollection.GetService<TfsTeamService>();
27: this.identityManagementService = this.teamProjectCollection.GetService<IIdentityManagementService>();
28: ICommonStructureService4 cssService = this.teamProjectCollection.GetService<ICommonStructureService4>();
29: this.projectInfo = cssService.GetProjectFromName(teamProjectName);
30: //Debug.WriteLine(this.identityManagementService.GetType().FullName);
31:
32: // 20120612 - WPS: Authenticates the connection to Team Foundation Server if it has not been previously authenticated
33: this.teamProjectCollection.EnsureAuthenticated();
34: }
35:
36: public void Dispose()
37: {
38: this.teamProjectCollection.Dispose();
39: }
40:
41: public List<string> ListTeams()
42: {
43: var teams = this.teamService.QueryTeams(this.projectInfo.Uri);
44: return (from t in teams select t.Name).ToList();
45: }
46:
47: public Guid CreateTeam(string team, string description)
48: {
49: TeamFoundationTeam t = this.teamService.CreateTeam(this.projectInfo.Uri, team, description, null);
50: return t.Identity.TeamFoundationId;
51: }
52:
53: public bool AddUser(string team, string user, out string message)
54: {
55: message = string.Empty;
56: bool ret = true;
57: TeamFoundationTeam t = this.teamService.ReadTeam(this.projectInfo.Uri, team, null);
58: TeamFoundationIdentity i = this.identityManagementService.ReadIdentity(IdentitySearchFactor.AccountName, user, MembershipQuery.Direct, ReadIdentityOptions.None);
59:
60: if (t == null)
61: {
62: message = "Team [" + team + "] not found";
63: ret = false;
64: }
65:
66: if (i == null)
67: {
68: message = "User [" + user + "] not found";
69: ret = false;
70: }
71:
72: if (ret)
73: {
74: this.identityManagementService.AddMemberToApplicationGroup(t.Identity.Descriptor, i.Descriptor);
75: message = "User added ";
76: }
77:
78: return ret;
79: }
80: }
81: }
Also please add your candid feedback and comments to this post!
My Quick Response Sample - a PowerShell module to manage Team Foundation Server Teams and Users.
github.com/.../PsTfsTeams
By implementing the exact same functionality as the sample command-line utility with a PowerShell module instead, we get a much richer model for post-processing the results of the commands and much easier ways to provide bulk input to the commands.
Jason
@J Stangroome, thanks for sharing your PowerShell module which is, as you stated, a powerful alternative. Giulio Vian, who is our Mr. PowerShell, will love your quick response sample :)
Wow, we always Impressed with this kind of work, keep up!
We have just fixed the Quick Response download package on vsarguidance.codeplex.com/.../96222. To avoid further unplanned over-writes, we have created a quick response dedicated download package.