'Disable azure devops repos with az-cli comand

i need to disable repositories in azure devops, in gui we can do it on setting item, but...

is there an az-cli comand to disable repositories?

someting like "az repos settings ..."



Solution 1:[1]

The azure cli to update the repostiroy is "az repos update", however it appears it only updates the default branch(--default-branch) or repository name "--name".

As an alternative, you can use rest api "Repositories - Update" to update the repo setting. Code sample:

Param(
   [string]$org = "orgname",
   [string]$project = "projectname",
   [string]$repositoryId = "repositoryid",
   [string]$token = "PAT"  
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$json = '{ "isDisabled" : "true" }'
$uri = "https://dev.azure.com/$org/$project/_apis/git/repositories/$repositoryId" + "?api-version=6.0"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wade zhou - MSFT