Azure Devops - Azure boards / teams with no work items

70 Views Asked by At

I am looking for any PowerShell az DevOps/ az boards code that can get the list of boards in a project where there are no workitems ever. I don't think any WIQL is out there but correct me if I am wrong.

1

There are 1 best solutions below

0
On

You may try the below approach.

$organizationName = "<organization-name>"
$projectName = "<project-name>"
$personalAccessToken = "<personal-access-token>"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$personalAccessToken"))
$headers = @{ Authorization = "Basic $token" }

$uri = "https://dev.azure.com/$organizationName/$projectName/_apis/work/boards?api-version=6.0-preview.1"
$boards = (Invoke-RestMethod -Method Get -Uri $uri -Headers $headers).value

$uri = "https://dev.azure.com/$organizationName/$projectName/_apis/wit/workitemtypes?api-version=6.0"
$workItemTypes = (Invoke-RestMethod -Method Get -Uri $uri -Headers $headers).value.name

$boardsWithNoWorkItems = @()
foreach ($board in $boards) {
    $boardId = $board.id
    $uri = "https://dev.azure.com/$organizationName/$projectName/_apis/work/boards/$boardId/columns?api-version=6.0-preview.1"
    $columns = (Invoke-RestMethod -Method Get -Uri $uri -Headers $headers).value
    $columns = $columns | Where-Object { $_.isSplit == $false }
    foreach ($column in $columns) {
        $columnId = $column.id
        $uri = "https://dev.azure.com/$organizationName/$projectName/_apis/work/boards/$boardId/columns/$columnId/cards?api-version=6.0-preview.1"
        $cards = (Invoke-RestMethod -Method Get -Uri $uri -Headers $headers).value
        $cards = $cards | Where-Object { $workItemTypes -notcontains $_.workItemType }
        if ($cards.Count -eq 0) {
            $boardsWithNoWorkItems += $board.name
            break
        }
    }
}

# Output with the list of boards with no workitems
$boardsWithNoWorkItems