Skip to content

Fix Get-AzDataProtectionJob returning only first page of backup jobs - #29900

Open
a0x1ab with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-get-azdataprotectionjob-limited-results
Open

Fix Get-AzDataProtectionJob returning only first page of backup jobs#29900
a0x1ab with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-get-azdataprotectionjob-limited-results

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Get-AzDataProtectionJob returns a truncated list when a vault has many jobs (e.g. 259 of 650+). The AutoRest-generated internal cmdlet makes a single HTTP GET and discards the nextLink in the response, so pagination never occurs.

Changes

  • Get-AzDataProtectionJob.ps1 — For the List parameter set (no -Id, -InputObject, or -UseSecondaryRegion), replaced the single internal cmdlet call with an Invoke-AzRestMethod pagination loop that follows nextLink until exhausted. Handles multiple subscription IDs. Injects AzureBackupJobResource type names on returned objects to preserve table formatting.
  • Single-item paths (-Id, -InputObject, -UseSecondaryRegion) are unchanged.
  • ChangeLog.md — Added entry under ## Upcoming Release.
# Before: returns first page only (~200-300 jobs)
Get-AzDataProtectionJob -VaultName $vaultName -ResourceGroupName $rg | Measure-Object
# Count: 259

# After: follows nextLink across all pages
Get-AzDataProtectionJob -VaultName $vaultName -ResourceGroupName $rg | Measure-Object
# Count: 657

Copilot AI requested review from Copilot and removed request for Copilot July 27, 2026 02:06
@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-client-tools-agent

Copy link
Copy Markdown

Live test skipped

⏭️ Skipping the live test for this revision because no changed test file was found under a <Service>.Test project (src/<Service>/<Service>.Test/**/*.cs|*.ps1).

The live-test pipeline runs only the scenario/xUnit test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically.


Posted by agent-assist (autonomous bug-fix pipeline).

Copilot AI requested review from Copilot and removed request for Copilot July 27, 2026 02:17
Copilot AI changed the title [WIP] Fix Get-AzDataProtectionJob to return all backup jobs Fix Get-AzDataProtectionJob returning only first page of backup jobs Jul 27, 2026
Copilot AI requested a review from a0x1ab July 27, 2026 02:19
@azure-client-tools-agent

Copy link
Copy Markdown

Live test skipped

⏭️ Skipping the live test for this revision because no changed test file was found under a <Service>.Test project (src/<Service>/<Service>.Test/**/*.cs|*.ps1).

The live-test pipeline runs only the scenario/xUnit test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically.


Posted by agent-assist (autonomous bug-fix pipeline).

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Review Summary

Status: ✅ Pass

  • CI checks: 1/1 completed and passed, 0 failed, 0 pending.
  • Live test (TestFx Record): Skipped — this PR does not modify any <Service>.Test/**/*.cs|*.ps1 files, so there is nothing for the live-test workflow to run against.

No outstanding failures. Flipping this PR out of draft so a human reviewer can take a look.


Posted by agent-assist (autonomous bug-fix pipeline).

@azure-client-tools-agent
azure-client-tools-agent Bot marked this pull request as ready for review July 27, 2026 02:22
Copilot AI review requested due to automatic review settings July 27, 2026 02:22
@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot could not run the full agentic suite for this review because it was automatically requested on a bot-authored pull request. Request a review from Copilot under Reviewers to retry with the full agentic suite. Improved support for bot-authored pull requests is coming soon.

This PR addresses Get-AzDataProtectionJob returning only the first page of jobs by adding explicit pagination handling so all backup jobs are returned for vaults with many jobs.

Changes:

  • Added an entry to the DataProtection changelog describing the pagination fix and linking to the tracked issue.
  • Updated Get-AzDataProtectionJob to follow nextLink and aggregate results across pages in the list scenario.
  • Kept single-item retrieval behavior when -Id or -InputObject is provided.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/DataProtection/DataProtection/ChangeLog.md Documents the pagination fix for Get-AzDataProtectionJob.
src/DataProtection/DataProtection.Autorest/custom/Cmdlets/Platform/Job/Get-AzDataProtectionJob.ps1 Implements paging by calling ARM and iterating nextLink for list results.

Comment on lines +149 to +154
foreach($job in $content.value){
$psObj = [PSCustomObject]$job
$psObj.PSObject.TypeNames.Insert(0, "Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.AzureBackupJobResource")
$psObj.PSObject.TypeNames.Insert(0, "Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.AzureBackupJobResource#Multiple")
Write-Output $psObj
}
Comment on lines +133 to +138
# List case: implement pagination by following nextLink
$subscriptionIds = if($PSBoundParameters.ContainsKey("SubscriptionId")) { $SubscriptionId } else { @((Get-AzContext).Subscription.Id) }
$apiVersion = "2026-03-01"

foreach($subId in $subscriptionIds){
$url = "https://management.azure.com/subscriptions/$subId/resourceGroups/$ResourceGroupName/providers/Microsoft.DataProtection/backupVaults/$VaultName/backupJobs?api-version=$apiVersion"
Comment on lines +141 to +146
$response = Invoke-AzRestMethod -Uri $url -Method GET
if($response.StatusCode -ne 200){
$errorContent = $response.Content | ConvertFrom-Json
$errorMessage = if($errorContent.error) { $errorContent.error.message } else { $response.Content }
throw "Failed to list backup jobs. Status: $($response.StatusCode). Error: $errorMessage"
}
else{
# List case: implement pagination by following nextLink
$subscriptionIds = if($PSBoundParameters.ContainsKey("SubscriptionId")) { $SubscriptionId } else { @((Get-AzContext).Subscription.Id) }
$apiVersion = "2026-03-01"
Comment on lines +21 to +23
* Fixed `Get-AzDataProtectionJob` returning only the first page of backup jobs instead of all jobs when a vault has many jobs
- The cmdlet now follows pagination links to retrieve all backup jobs from the vault
- Fixed issue [#29899]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-AzDataProtectionJob returns limited number of backup jobs

3 participants