I am trying get the release details for my project using PowerShell and API but I am not able to get more than 100 results and also getting this error "A parameter cannot be found that matches parameter name '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
was added in PowerShell 6.0.0. Please run $PSVersionTable
on your machine to check the version of your PowerShell. If it's lower than 6.0.0, follow this doc Installing PowerShell on Windows to install the latest version.
The following scripts work fine on my side.
$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"