How to get total repo size of all organizations in Azure DevOps ?

Cheng, Man Lam 21 Reputation points
2025-01-24T21:58:27.45+00:00

HI

does any know how to get a total repo size of all organizations in Azure DevOps?

Thanks

Community Center | Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. David Pazdera 396 Reputation points
    2025-01-25T19:52:44.45+00:00

    Hi,

    I am not aware of any dashboard in Azure DevOps that gives this overview across several organizations, only on individual project and repository level (in Files - Health and usage).

    However, you should be able to get this data by calling Azure DevOps REST API, for example by using PowerShell.

    The example below collects it for a single project but by using loops (an inner loop for all projects within a single org and an outer loop to query all ADO organizations) you should get a good output:

    $organization = "your_organization"
    $project = "your_project"
    $pat = "your_personal_access_token"
    $uri = "https://dev.azure.com/$organization/$project/_apis/git/repositories?api-version=6.0"
    $headers = @{
        Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))
    }
    $response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers
    $repositories = $response.value
    $totalSize = 0
    foreach ($repo in $repositories) {
        $repoUri = "https://dev.azure.com/$organization/$project/_apis/git/repositories/$($repo.id)/stats?api-version=6.0"
        $repoResponse = Invoke-RestMethod -Uri $repoUri -Method Get -Headers $headers
        $totalSize += $repoResponse.size
    }
    Write-Output "Total size of all repositories: $totalSize bytes"
    
    

    Apart from using Invoke-RestMethod cmdlet, there is a module available in the PowerShell Gallery that could help as well - VSTeam - with Get-VSTeamGitRepository cmdlet.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.