我正在尝试使用 PowerShell 和 API 获取我的项目的发布详细信息,但我无法获得超过 100 个结果,并且还收到此错误“找不到与参数名称“ResponseHeadersVariable”匹配的参数
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string] $AzureDevOpsPAT,
[Parameter(Mandatory=$true)]
[string] $OrganizationName,
[Parameter(Mandatory=$true)]
[string] $Project
)
$minCreatedTime = "2024-02-01T00:00:00.00Z"
$maxCreatedTime = "2024-03-31T23:59:59.00Z"
$folder= "\Web"
$count = "1000"
$User=""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,$AzureDevOpsPAT)))
# $header = @{Authorization=("Basic {0}" -f $base64AuthInfo)}
# Get pipelines
$pipelines = "https://vsrm.dev.azure.com/$OrganizationName/$Project/_apis/release/releases?api-version=7.0&path=$folder&minCreatedTime=$minCreatedTime&maxCreatedTime=$maxCreatedTime&`$top=$count"
# $totalpipeline = Invoke-RestMethod -Uri $pipelines -Method Get -ContentType application/json -Headers $header
$url = $pipelines
$results = @();
do
{
write-host "Calling API"
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = ("Basic $token" -f $base64AuthInfo)} -Method Get -ContentType application/json -ResponseHeadersVariable headers
$results += $response.value
if ($headers["x-ms-continuationtoken"])
{
$continuation = $headers["x-ms-continuationtoken"]
write-host "Token: $continuation"
$url = $pipelines + "&continuationToken=" + $continuation
}
} while ($headers["x-ms-continuationtoken"])
$results
Need to get more than 100 results of release ID.
-ResponseHeadersVariable
。请在您的计算机上运行 $PSVersionTable
以检查 PowerShell 的版本。如果低于 6.0.0,请按照此文档在 Windows 上安装 PowerShell 安装最新版本。
以下脚本在我这边运行良好。
$urlBase="https://vsrm.dev.azure.com/{Org name}/{Project name}/_apis/release/releases?api-version=7.1-preview.8&`$top=500"
$url = $urlBase
$results = @();
$token = "{PAT}"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
do
{
write-host "Calling API"
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json -ResponseHeadersVariable headers
$results += $response.value
if ($headers["x-ms-continuationtoken"])
{
$continuation = $headers["x-ms-continuationtoken"]
write-host "Token: $continuation"
$url = $urlBase + "&continuationtoken=" + $continuation
}
} while ($headers["x-ms-continuationtoken"])
$results | Out-File -FilePath "output.txt"