Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download all repositories for a GitHub organization
Function Download-GitHubRepos ([string][parameter(mandatory=$true)] $orgid, [string]$saveLocation)
{
if (-not ([string]::IsNullOrEmpty($saveLocation)))
{
if (-not (Test-Path $saveLocation -PathType Container))
{
Throw "saveLocation is invalid"
}
if (-not ($saveLocation.EndsWith('\')) -or ($saveLocation.EndsWith('/')))
{
$saveLocation = $saveLocation + '\'
}
}
$reposUrl = 'https://api.github.com/orgs/' + $orgid + '/repos'
$repos = Invoke-RestMethod $reposUrl
foreach ($repo in $repos)
{
$downloadUrl = $repo.html_url + '/archive/master.zip'
$outputFile = $saveLocation + $repo.name + '.zip'
Invoke-WebRequest $downloadUrl -OutFile $outputFile
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.