Querying Lab Environments Using TFS Lab Management APIs

Subramanyam [MSFT]

using System;

using System.Collections.Generic;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.Lab.Client;

namespace QueryLabEnvironment 




        staticvoid Main(string[] args) 


            //Get reference to lab service

            TfsTeamProjectCollection tfsServer = newTfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(“http://<ATName>:8080/tfs”));

            LabService labService = (LabService)tfsServer.GetService(typeof(LabService));

            //Create lab environment query specifications object

            LabEnvironmentQuerySpec querySpec = newLabEnvironmentQuerySpec();

            querySpec.Project = “ProjectName”;

            //Run the query using lab service

            ICollection<LabEnvironment> envList = labService.QueryLabEnvironments(querySpec);

            LabEnvironment myLE = null;

            //Search for required environment

            foreach (LabEnvironment env in envList) 


                if (env.Name == “LEName”) 


                    myLE = env; 




     //Iterate over all the lab systems

      foreach (LabSystem labSystem in myLE.LabSystems) 


            Console.WriteLine(“Lab System Name {0}, labSystem.ComputerName); 







Discussion is closed.

Feedback usabilla icon