Created
September 26, 2015 21:26
-
-
Save prasannavl/1e228133e197a9c92c88 to your computer and use it in GitHub Desktop.
Clone all the repos for a given GitHub username.
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 Clone-AllGitHubRepos | |
{ | |
<# | |
.SYNOPSIS | |
Clone all GitHub Repositories of a given user. | |
.DESCRIPTION | |
Recursively clone all the repos for a given username. | |
.EXAMPLE | |
Clone-AllGitHubRepos -User "aspnet" | |
#> | |
[cmdletbinding()] | |
param( | |
[string]$User, | |
[string]$Destination, | |
[string]$ApiUrl = "https://api.github.com/users/$User/repos", | |
[string]$UserAgent = "Powershell" | |
) | |
Write-Verbose ("User: " + $User) | |
Write-Verbose ("ApiUrl: " + $ApiUrl) | |
$wc = New-Object System.Net.WebClient | |
if ($UserAgent) { | |
Write-Verbose ("Using user-agent: " + $UserAgent) | |
$wc.Headers.Add("User-agent", "$UserAgent") | |
} | |
$json = $wc.DownloadString($ApiUrl) | |
$res = ConvertFrom-Json $json | |
if ($Destination) { | |
Write-Verbose ("Using destination dir: " + $Destination) | |
cd $Destination | |
} | |
$res | % { Write-Verbose "$($_.name): $($_.html_url)"; git clone $_.html_url } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment