Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kiwimato/1a47d25226268dd5f580cbd45cb6f741 to your computer and use it in GitHub Desktop.
Save kiwimato/1a47d25226268dd5f580cbd45cb6f741 to your computer and use it in GitHub Desktop.
This script will help with updating multiple Azure DevOps repositories at once, useful when there are too many repos to point and click
# This script will help with updating multiple Azure DevOps repositories at once, useful when there are too many repos to point and click
# For example on line 23, the command updates all repos that match PATTERN to only allow squash merge types.
$org="organization"
$project="Project"
$PAT="XXPATXX"
# First login:
az devops configure --defaults organization=https://dev.azure.com/$org project=$project
# Get a PAT and replace PAT here:
Write-Output $PAT | az devops login --organization "https://dev.azure.com/$org"
# Get all repos
$listOfRepos = az repos list | ConvertFrom-Json
# Replace "PATTERN" with your repo pattern, for example: wealth
$reposIds = $listOfRepos | Where-Object{$_.name -like "PATTERN*"} | %{$_.id}
# Update policy
foreach $(repoId from $reposIds){
az repos policy merge-strategy create --repository-id $repoId --blocking true --branch master --enabled --allow-no-fast-forward false --allow-rebase false --allow-rebase-merge false --allow-squash true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment