Partager via


Unregister a Data Collector from TFS

 

When a test agent connects successfully with a test controller, it also registers collectors that it had discovered. However when these collector are removed from the agent, they don’t get unregistered and linger on in the TFS. There’s no UI to achieve the same today. The below piece of code comes handy in unregistering a collector.

TfsTeamProjectCollection tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(<TFS Server>));

            ITestManagementService testManagementService = tfsCollection.GetService<ITestManagementService>();

 

            List<IDataCollectorInformation> unregister = new List<IDataCollectorInformation>();

            foreach (var collectorInfo in testManagementService.DataCollectors.Query())

            {

                if (<condition to match the collector to be marked for unregister>)

                {

                    unregister.Add(collectorInfo);

                }

            }

 

            if (unregister.Count > 0)

            {

                testManagementService.DataCollectors.Unregister(unregister);

            }