Last active
May 30, 2023 01:14
-
-
Save itaysk/41bb2cf7cbc8559e0617 to your computer and use it in GitHub Desktop.
Download all repositories for a GitHub organization
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 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