I have number of projects in Azure DevOps. I want to able to iterate through all Repos in Azure DevOps and get the name of the Repo, Creator of Repo and Last Updated/commit.
And get a notification when some one created new Repo?
I have number of projects in Azure DevOps. I want to able to iterate through all Repos in Azure DevOps and get the name of the Repo, Creator of Repo and Last Updated/commit.
And get a notification when some one created new Repo?
We can list the repo info via REST API
List all repositories and get the name of the repo:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.1-preview.1
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=6.1-preview.1
Note: we can get the branch creator via this API, I didn't find any APIs to get the repo creator.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?searchCriteria.$top=1&api-version=6.1-preview.1
Get a notification when some one created new Repo
We cannot create this notification, we can get a notification when someone updated the repo code. Please refer this link for more details: Supported event types
Update1
//List project name
$connectionToken="PAT"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$ProjectUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.1-preview.1"
$Repo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$RepoName= $Repo.value.name
Write-Host $RepoName
//get latest commit info and branch creator
$RepoID=$Repo.value.id
Write-Host $RepoID
ForEach ($Id in $RepoID)
{
//Get latest commit info
$ProjectUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/commits?api-version=6.1-preview.1"
$CommitInfo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
$CommitID = $CommitInfo.value.commitId | Select-Object -first 1
Write-Host $CommitID
$CommitUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/commits/$($CommitID)?api-version=6.0-preview.1"
$LatestCommitInfo = (Invoke-RestMethod -Uri $CommitUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host "LatestCommitInfo = $($LatestCommitInfo | ConvertTo-Json -Depth 100)"
//Get branch name and creatot
$BarchCreatorUrl = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/$Id/refs?api-version=6.1-preview.1"
$CreateorInfo = (Invoke-RestMethod -Uri $BarchCreatorUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host $CreateorInfo.value.name
Write-Host $CreateorInfo.value.creator.displayName
}
https://{organization}.visualstudio.com/{project}/_apis/git/repositories?api-version=6.1-preview.1
–
Silicle Another option (easier with the Auth part) is to retrieve your Azure Repositories is through the AZ CLI using following commands:
Log into Azure
az login -t $tenant
First configure default values for organization and project, this
will help you to not specify --project
and --organization
parameters
in every az devops/repos command:
az devops configure -d organization=$organizationUrl project=$project
List repositories of your subscription and default project and organization
az repos list --subscription $subscription
Install-Module -Name VSTeam
$pat="YYYY"
Set-VSTeamAccount https://dev.azure.com/dXXXX/ -PersonalAccessToken $pat
Get-VSTeamGitRepository
or you can run this script (if az devops doesn't work, then add the azure-devops extension) and remember to replace URL-of-your-ado-org with your real URL:
# will be prompted to log in via browser
az login
# get all your ADO projects in your org in json format
$adoprojs = az devops project list
# convert to powershell object
$projObjs = $adoprojs | ConvertFrom-Json
# loop through each ADO project and find it's repos
foreach ($proj in $projObjs.value.name) {
write-host "looking in $proj ADO project for repos"
# set to specific ADO project
az devops configure --defaults organization=URl-of-your-ado-org project=$proj
# now get it's repos (in json)
$jsonRepos = az repos list
# convert repos from json format to powershell object
$RepoObjs = $jsonRepos | ConvertFrom-Json
# now list each repo
foreach ($repo in $RepoObjs) {
write-host " " $repo.name
}
}
© 2022 - 2025 — McMap. All rights reserved.