Skip to content

Instantly share code, notes, and snippets.

@EricRohlfs
Created July 14, 2016 19:23
Show Gist options
  • Save EricRohlfs/2f16d98674482214cb0fddc9169492b4 to your computer and use it in GitHub Desktop.
Save EricRohlfs/2f16d98674482214cb0fddc9169492b4 to your computer and use it in GitHub Desktop.
# Downloads all the git projects from a Microsoft Visual Studio Team Services (VSTS) account.
# Helpful if a team has many git repositories.
# change these
$project = "myProject"
$whereToSaveRoot = "d:\myProject\"
# application start
$username = Read-Host -Prompt 'UserName from VSTS Alt Credentials'
# tried as secure string, it did not work consistently
$password = Read-Host -Prompt 'Password from VSTS Alt Credentials'
$basicAuth = ("{0}:{1}" -f $username,$password)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}" -f $basicAuth)}
# change mycompany to yourcompany
$listOfProjectRepos = Invoke-RestMethod -Uri https://mycompany.visualstudio.com/defaultcollection/$project/_apis/git/repositories?api-version=1.0 -headers $headers -Method Get
foreach($item in $listOfProjectRepos.value){
$saveTo = -join($whereToSaveRoot, $item.name)
$exists = Test-Path $saveTo
if(-Not $exists){
#change myProjectTeamName and myCompany
$repoUrl = -join("https://myCompany.visualstudio.com/DefaultCollection/myProjectTeamName/_git/",$item.name)
$cloneCmd = "git clone $repoUrl $saveTo"
Write-Host $cloneCmd;
Invoke-Expression $cloneCmd;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment