Using the TFS 2013 API along with a little PowerShell we can add a ‘team field’ to our global list.
I have been working a lot with PowerShell recently and I have been stuck by its flexibility even when calling standard .NET API’s. You should start with geting the TFS Collection which will give you basic connectivity and imports required to get started. If we want to use ’team field’ we may want to automate some of the activities that we need to make it happen slickly. You will have created a Global List for your ’team field’ and you will want to add new entries. You can add them manually, or you can hit the TFS API to give you a leg up…
In order to add an entry to a global list we unfortunately need to export all of the global lists locally as XML, edit it and then upload it back in. I have been trying to create as many reusable functions as possible in my PowerShell exploits and I am building up a rather hearty set of components. I have not yet figured out how to create reusable components that can be easily imported but I have figured out functions:
function Add-TfsGlobalListItem {
Param(
[parameter(Mandatory=$true)][Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $TfsCollection,
[parameter(Mandatory=$true)][String] $GlobalListName,
[parameter(Mandatory=$true)][String] $GlobalEntryValue
)
# Get Global List
$store = Get-TfsWorkItemStore $TfsCollection
[xml]$export = $store.ExportGlobalLists();
$globalLists = $export.ChildNodes[0];
$globalList = $globalLists.SelectSingleNode("//GLOBALLIST[@name='$GlobalListName']")
# if no GL then add it
If ($globalList -eq $null)
{
$globalList = $export.CreateElement("GLOBALLIST");
$globalListNameAttribute = $export.CreateAttribute("name");
$globalListNameAttribute.Value = $GlobalListName
$globalList.Attributes.Append($globalListNameAttribute);
$globalLists.AppendChild($globalList);
}
#Create a new node.
$GlobalEntry = $export.CreateElement("LISTITEM");
$GlobalEntryAttribute = $export.CreateAttribute("value");
$GlobalEntryAttribute.Value = $GlobalEntryValue
$GlobalEntry.Attributes.Append($GlobalEntryAttribute);
#Add new entry to list
$globalList.AppendChild($GlobalEntry)
# Import list to server
$store.ImportGlobalLists($globalLists)
}
Figure: Adding to a GlobalList with PowerShell
Here you can see that we are first getting the Work Item Store service, which is where all of the magic around Work Item Tracking occurs. Once we have that we need to export the XML using the “ExportGlobalLists” (#9) method which effectively just pucks up the entire XML tree for the global lists. We can then parse and edit it like any other piece of XML. We can find the list that we want, as all of the lists are exported, using a little XPath (#11) and determine wither the required global list even exists. If it does not then my script goes ahead and adds one (#14-21) so that we don’t get an error. If this is the first time that you are added and element to a list it only makes sense that you would want the list to exist so creating it is not a stretch.
Once we have the list, wither it is a new or existing one, we can go ahead and create and add the new element (#24-27.) Once we have everything in place we can import the entire set of global lists back into the server using the Import method.
Smart Classifications
Each classification [Concepts, Categories, & Tags] was assigned using AI-powered semantic analysis and scored across relevance, depth, and alignment. Final decisions? Still human. Always traceable. Hover to see how it applies.
What to read next
PowerShell TFS 2013 API #1 - Get TfsCollection and TFS Services
Learn how to use PowerShell to connect to TFS 2013, import required assemblies, and access core TFS services like Work Item Store, Version …
Teams without areas using a team field in TFS
Explains how to configure TFS to manage teams using a custom team field instead of area paths, enabling flexible team-product assignments …
Modelling Teams in Team Foundation Server 2013
Guidance on structuring teams, areas, iterations, source control, and security in Team Foundation Server 2013 to support project management …
Detecting agile theatre with real delivery signals
Why Most Companies Operating Models Fail in Dynamic Markets
A concise comparison of Predictive and Adaptive Operating Models, explaining why traditional structures fail in dynamic markets and how …
Don’t Manage Dependencies, Remove Them
Explains why dependencies are a sign of poor system design and outlines steps to eliminate them by aligning teams, clarifying ownership, and …
The Estimation Trap: How Tracking Accuracy Undermines Trust, Flow, and Value in Software Delivery
Tracking estimation accuracy in software delivery leads to mistrust, fear, and distorted behaviours. Focus on customer value, flow, and …
Flow of Value vs Flow of Work – Misnomer or Useful Shorthand?
Compares “flow of value” and “flow of work” in Kanban, explaining why only validated outcomes count as value and stressing the need for …
Why Outsourcing DevOps Fails, and How Real Engineering Excellence Starts With Your Team
Avoid DevOps vendor lock-in, discover how true engineering excellence starts with partnership, not outsourcing. Ready to transform your …
Detecting agile theatre with real delivery signals
Don’t Manage Dependencies, Remove Them
Explains why dependencies are a sign of poor system design and outlines steps to eliminate them by aligning teams, clarifying ownership, and …
The Estimation Trap: How Tracking Accuracy Undermines Trust, Flow, and Value in Software Delivery
Tracking estimation accuracy in software delivery leads to mistrust, fear, and distorted behaviours. Focus on customer value, flow, and …
Flow of Value vs Flow of Work – Misnomer or Useful Shorthand?
Compares “flow of value” and “flow of work” in Kanban, explaining why only validated outcomes count as value and stressing the need for …
Why Outsourcing DevOps Fails, and How Real Engineering Excellence Starts With Your Team
Avoid DevOps vendor lock-in, discover how true engineering excellence starts with partnership, not outsourcing. Ready to transform your …
Estimating Better in an Overloaded System Is a Poor Man’s Strategy
High work in progress (WIP) causes delays and unpredictability; improving estimates won’t help. Limiting WIP and focusing on flow is key to …