Created
December 29, 2019 06:17
-
-
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.
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
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