You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PowerShell 5.1获取Azure DevOps指定日期范围已完成PR遇参数问题

解决Azure DevOps PR查询中closedDate参数失效的问题

问题原因

URL里直接使用>作为日期比较运算符时,会被视为非法字符,Azure DevOps API无法正确解析这个过滤条件,导致closedDate参数不生效。

修正方案

方案1:手动编码比较运算符

将URL中的>替换为对应的URL编码%3E,确保API能识别比较条件:

$startDate = (Get-Date -Date "2025-01-31T00:00:00Z").ToString("yyyy-MM-ddTHH:mm:ssZ")

$url = "$organization/$project/_apis/git/repositories/$repositoryId/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.closedDate%3E$startDate&api-version=6.0"

方案2:用PowerShell自动编码

使用[Uri]::EscapeDataString()方法自动处理特殊字符,避免手动编码出错:

$startDate = (Get-Date -Date "2025-01-31T00:00:00Z").ToString("yyyy-MM-ddTHH:mm:ssZ")
$closedDateCondition = [Uri]::EscapeDataString(">${startDate}")

$url = "$organization/$project/_apis/git/repositories/$repositoryId/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.closedDate=$closedDateCondition&api-version=6.0"

扩展:查询日期范围

如果需要查询某个时间段内的PR,同时添加结束日期过滤,记得把<编码为%3C:

$startDate = (Get-Date -Date "2025-01-31T00:00:00Z").ToString("yyyy-MM-ddTHH:mm:ssZ")
$endDate = (Get-Date -Date "2025-02-28T23:59:59Z").ToString("yyyy-MM-ddTHH:mm:ssZ")

$url = "$organization/$project/_apis/git/repositories/$repositoryId/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/master&searchCriteria.closedDate%3E$startDate&searchCriteria.closedDate%3C$endDate&api-version=6.0"

内容的提问来源于stack exchange,提问作者Rod

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:02:10