Created
September 28, 2020 21:16
-
-
Save jpeckham/303c905f9f4114dc49719699e1fe6fb5 to your computer and use it in GitHub Desktop.
CloneAllRepos.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = "https://your devops url" | |
$username = "yourname@company.com" | |
$password = "access token" | |
# Retrieve list of all repositories | |
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password))) | |
$headers = @{ | |
"Authorization" = ("Basic {0}" -f $base64AuthInfo) | |
"Accept" = "application/json" | |
} | |
Add-Type -AssemblyName System.Web | |
$gitcred = ("{0}:{1}" -f [System.Web.HttpUtility]::UrlEncode($username),$password) | |
$uri = ("{0}/_apis/git/repositories?api-version=1.0" -f $url) | |
Write-Host $uri | |
$resp = Invoke-WebRequest -Headers $headers -Uri $uri | |
$json = convertFrom-JSON $resp.Content | |
# Clone or pull all repositories | |
$initpath = get-location | |
foreach ($entry in $json.value) { | |
$name = $entry.name | |
Write-Host $name | |
$url = $entry.remoteUrl | |
if(!(Test-Path -Path $name)) { | |
git clone $url | |
} else { | |
set-location $name | |
git pull | |
set-location $initpath | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment