Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active December 6, 2019 16:31
Show Gist options
  • Save ljtill/17eb1e501137c9e607e68e15690358c3 to your computer and use it in GitHub Desktop.
Save ljtill/17eb1e501137c9e607e68e15690358c3 to your computer and use it in GitHub Desktop.
Provides the ability to clone all Azure DevOps repositories
function Invoke-AzureDevOpsRepositoriesClone {
[CmdletBinding()]
param (
[Parameter()]
[string]$AccountName,
[Parameter()]
[string]$ProjectName,
[Parameter()]
[string]$Username,
[Parameter()]
[string]$PersonalAccessToken
)
begin {
$apiVersion = "4.1"
$request = @{
Method = "GET"
Uri = ("https://" + $accountName + ".visualstudio.com/" + $projectName + "/_apis/git/repositories?api-version=" + $apiVersion)
Headers = @{
"Authorization" = ("Basic " + ([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $personalAccessToken)))))
"Accept" = "application/json"
}
Body = $null
}
}
process {
$response = Invoke-RestMethod @request
$response.value | ForEach-Object {
git clone $_.remoteUrl
}
}
end {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment