我的目标是提出一个Powershell脚本来清理XAML构建代理的工作目录。
要获取构建代理的工作目录,我可以使用下面的C#代码,这可以正常工作。
我想在Powershell中实现相同的功能。
static void Main(string[] args)
{
var TPC = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("CollectionURI"));
IBuildServer buildServer = TPC.GetService<IBuildServer>();
\\ {Microsoft.TeamFoundation.Build.Client.BuildServer}
var buildController = buildServer.GetBuildController("ControllerName");
var buildAgent = buildController.Agents;
var workingFolder = string.Empty;
List<string> list = new List<string>();
foreach (IBuildAgent agent in buildAgent)
{
list.Add(agent.BuildDirectory);
}
}
如果无法找到Powershell等效项,我将不得不通过exe或dll在Powershell中使用C#。
答案 0 :(得分:1)
它类似于您的C#代码:
$url = "http://xxxx:8080/tfs/CollectionName/";
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($url);
$buildservice = $tfs.GetService("Microsoft.TeamFoundation.Build.Client.IBuildServer");
$buildcontroller = $buildservice.GetBuildController("ControllerName");
$buildagents = $buildcontroller.Agents;
foreach($buildagent in $buildagents)
{
Write-Host $buildagent.BuildDirectory;
}