Skip to content

Instantly share code, notes, and snippets.

@itaysk
Last active May 30, 2023 01:14
Show Gist options
  • Save itaysk/41bb2cf7cbc8559e0617 to your computer and use it in GitHub Desktop.
Save itaysk/41bb2cf7cbc8559e0617 to your computer and use it in GitHub Desktop.
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