Skip to content

Instantly share code, notes, and snippets.

@ajtatum
Created December 29, 2019 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajtatum/7840aef8fb21054f17c4d3bf8591bcd5 to your computer and use it in GitHub Desktop.
Save ajtatum/7840aef8fb21054f17c4d3bf8591bcd5 to your computer and use it in GitHub Desktop.
A short little PowerShell script that updates all the repositories in a given directory. In this scenario, I have an environment variable called repos that goes to that folder.
function Get-UrlStatusCode([string] $Url) {
try {
(Invoke-WebRequest -Uri $Url -UseBasicParsing -DisableKeepAlive).StatusCode
}
catch [Net.WebException] {
[int]$_.Exception.Response.StatusCode
}
}
$username = "";
$repos = @("","")
foreach ($repo in $repos) {
if (-not(Test-Path -Path $env:repos\$repo -PathType Container)) {
if (Get-UrlStatusCode https://github.com/$username/$repo/ == 200)
{
Set-Location -Path $env:repos
git clone https://github.com/$username/$repo/
}
elseif (Get-UrlStatusCode https://$username@dev.azure.com/$username/$repo/_git/$repo == 200)
{
Set-Location -Path $env:repos
git clone https://$username@dev.azure.com/$username/$repo/_git/$repo
}
else{
Write-Host "Cannot find repo for " + $repo + "." -BackgroundColor Red -ForegroundColor White
}
}
else {
Set-Location -Path $env:repos\$repo
git fetch
git pull --all
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment