Learn to use Visual Studio, Visual Studio Online, Application Insights and Team
Foundation Server to decrease rework, increase transparency into your application and increase the rate at which
you can ship high quality software throughout the application lifecycle
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
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;
16: internal class TeamWrapper : IDisposable
18: private readonly TfsTeamProjectCollection teamProjectCollection;
19: private readonly TfsTeamService teamService;
20: private readonly ProjectInfo projectInfo;
21: private readonly IIdentityManagementService identityManagementService;
23: public TeamWrapper(Uri collectionUri, string teamProjectName)
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);
32: // 20120612 - WPS: Authenticates the connection to Team Foundation Server if it has not been previously authenticated
36: public void Dispose()
41: public List<string> ListTeams()
43: var teams = this.teamService.QueryTeams(this.projectInfo.Uri);
44: return (from t in teams select t.Name).ToList();
47: public Guid CreateTeam(string team, string description)
49: TeamFoundationTeam t = this.teamService.CreateTeam(this.projectInfo.Uri, team, description, null);
50: return t.Identity.TeamFoundationId;
53: public bool AddUser(string team, string user, out string message)
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);
60: if (t == null)
62: message = "Team [" + team + "] not found";
63: ret = false;
66: if (i == null)
68: message = "User [" + user + "] not found";
69: ret = false;
72: if (ret)
74: this.identityManagementService.AddMemberToApplicationGroup(t.Identity.Descriptor, i.Descriptor);
75: message = "User added ";
78: return ret;
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.
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.
@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.