I'm building a tool for checking disk space on the TFS Build servers. I could just input a manual list but for longterm use, it's best if I could import the list of build servers from somewhere. I've connected to TFS with the following code
add-type -Path "C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools\Microsoft.TeamFoundation.Build.Workflow.dll"
$TFSURL = "http://tfs:8080/tfs/"
$TFS = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TFSURL)
$buildServer = $TFS.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
So you're looking for the Agents, and to get those you need to get the controllers that they're associated with, so you need to run the
QueryBuildControllers() method of your
$buildControllers = $buildServer.QueryBuildControllers() $buildControllers.Agents
I found this by doing a search for Client.IBuildServer on Google, and going to the first link to MSDN. From there I just looked for a method that would find all of something that looked relevant to servers, and saw the QueryBuildControllers method, followed it to see the return objects had a property named Agents, which should be what you're looking for.