Skip to content

Instantly share code, notes, and snippets.

@mdailey77
Created August 13, 2022 20:10
Show Gist options
  • Save mdailey77/d72b561913cf24956e3afb51716b65ed to your computer and use it in GitHub Desktop.
Save mdailey77/d72b561913cf24956e3afb51716b65ed to your computer and use it in GitHub Desktop.
An easy way to retrieve all the IDs of work item queries in a given Azure DevOps project
<# Azure DevOps REST API #>
$url = 'https://dev.azure.com/{organization_name}/{project_name}/_apis/wit/queries?$expand=all&$depth=2&$includeDeleted=false&api-version=7.1-preview.2'
$Token = '{Azure DevOps PAT}'
if ($Token -eq "") {
Write-Host 'PAT not set'
exit 1
}
$AzureAuthHeader = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $Token)))
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $AzureAuthHeader))
$headers.Add("Content-Type", "application/json")
$response = Invoke-RestMethod -Uri $url -Method GET -Headers $headers
$Items = $response.value
foreach ($Item in $Items) {
Write-Host "Parent Item" + $Item.name
$childItems = $Item.children
foreach ($child in $childItems) {
Write-Host $child.name
Write-Host $child.id
if ($child.hasChildren -eq "True") {
foreach ($secondchild in $child.children) {
Write-Host $secondchild.name
Write-Host $secondchild.id
Write-Host `r`n
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment