TFS 2015导出合集所有项目源码

TFS 2015 Export collection all projects source code

我需要一些帮助,了解如何一次性克隆我的 TFS 2015(更新 3)集合中的所有项目 (git)。我在下面找到了这个用于更新版本的 powershell 脚本,我尝试将 API 版本从 4.0 更改为 2.0,但随后出现错误 "Method invocation failed because [System.Management.Automation.PSCustomObject] doesn't contain a method named 'ForEach'."

无法找到如何在 TFS 2015 API 或任何其他方式中执行此克隆的示例。

$collection = "http://myserver:8080/tfs/DefaultCollection"

$projectsUrl = "$collection/_apis/projects?api-version=4.0"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -UseDefaultCredentials -ContentType application/json

$projects.value.ForEach({

  $reposUrl = "$collectionurl/$($_.name)/_apis/git/repositories?api-version=4.0"
  $repos = Invoke-RestMethod -Uri $reposUrl -Method Get -UseDefaultCredentials -ContentType application/json
  $repos.value.ForEach({
    git clone $_.remoteUrl --branch master --single-branch

  })
})

我成功了。第一个问题是我需要安装更新版本的 powershell。

之后它只是修复了脚本中的一些问题,下面是工作脚本。

$collection = "http://myserver:8080/tfs/DefaultCollection"

$projectsUrl = "$collection/_apis/projects?api-version=2.3-preview"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -UseDefaultCredentials -ContentType application/json -AllowUnencryptedAuthentication

$projects.value.ForEach({

  $reposUrl = "$collection/$($_.name)/_apis/git/repositories?api-version=2.3-preview"
  $repos = Invoke-RestMethod -Uri $reposUrl -Method Get -UseDefaultCredentials -ContentType application/json -AllowUnencryptedAuthentication
  $repos.value.ForEach({
    git clone $_.remoteUrl --branch master --single-branch

  })
})