通常,我们无法通过API直接实现这一点,因为没有明确的项目状态来确定项目是活动的还是非活动的。我们可以看到项目的状态都是“
wellFormed
“。请参阅
Get a list of team projects
但是,您可以使用工作项尝试API。基本上,如果所有相关工作项
完成
那么项目应该处于非活动状态。
参考下面的PS脚本示例,该示例使用
REST API
检索具有
多恩
工作项。(
0
方法
不活跃的
)
Param(
[string]$collectionurl = "http://server:8080/tfs/DefaultCollection",
[string]$keepForever = "true",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$projecturi = "$($collectionurl)/_apis/projects?api-version=1.0"
$projects = (Invoke-RestMethod -Uri $projecturi -Method Get -UseDefaultCredential).value.name
foreach ($project in $projects)
{
function CreateJsonBody
{
$value = @"
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [State] <> 'Done' AND [System.TeamProject]='$project' AND [System.ChangedDate] < '2018-01-01' AND [System.ChangedDate] > '2017-01-01' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
"@
return $value
}
$json = CreateJsonBody
$uri = "$($collectionurl)/_apis/wit/wiql?api-version=1.0"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
write-host "ProjectName:" $project : $result.workItems.Count
}