using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Lab.Client;
namespace QueryLabEnvironment
{
classProgram
{
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;
break;
}
}
//Iterate over all the lab systems
foreach (LabSystem labSystem in myLE.LabSystems)
{
Console.WriteLine(“Lab System Name {0}“, labSystem.ComputerName);
}
}
}
}
0 comments