Skip to content

Update GetAzSqlDeletedServer command - #30016

Open
rambabu-yalla wants to merge 3 commits into
Azure:mainfrom
rambabu-yalla:ramyal/updateAzSqlDeletedServerCommand
Open

Update GetAzSqlDeletedServer command#30016
rambabu-yalla wants to merge 3 commits into
Azure:mainfrom
rambabu-yalla:ramyal/updateAzSqlDeletedServerCommand

Conversation

@rambabu-yalla

@rambabu-yalla rambabu-yalla commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Description

Description
This PR enhances the Get-AzSqlDeletedServer cmdlet to support subscription-level queries by making the location parameter optional. It also adds ScheduledPurgeTime and Location output properties to the deleted server model for improved visibility into soft-deleted server information.
Upgraded deletedServer.Json to 2025-08-01-preview

Key changes:
Get-AzSqlDeletedServer: Made Location parameter optional to enable listing deleted servers across all locations at subscription level
Output Properties: Added ScheduledPurgeTime and Location to output properties to the deleted server model

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

Copilot AI lite review requested due to automatic review settings August 14, 2026 18: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.

@rambabu-yalla rambabu-yalla changed the title Ramyal/update az sql deleted server command Update GetAzSqlDeletedServer command Aug 14, 2026

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

This PR updates the Az.Sql deleted server experience by enabling subscription-level discovery of soft-deleted SQL servers (making -Location optional for Get-AzSqlDeletedServer) and by surfacing additional deleted-server metadata (ScheduledPurgeTime, Location) through the cmdlet model.

Changes:

  • Added a subscription-scoped deleted servers list path (SDK + communicator/adapter) and updated Get-AzSqlDeletedServer logic to use it when -Location is omitted.
  • Extended the deleted server output model with ScheduledPurgeTime and Location, and updated help + changelog accordingly.
  • Added/updated scenario and unit tests to cover the new parameter behavior and new output properties.

Reviewed changes

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

Show a summary per file
File Description
src/Sql/Sql/Server/Services/AzureSqlDeletedServerCommunicator.cs Adds subscription-level listing via DeletedServers.List() and renames location-scoped list method.
src/Sql/Sql/Server/Services/AzureSqlDeletedServerAdapter.cs Adds adapter method for subscription listing; updates deleted-server model mapping (incl. parsing location/subscription).
src/Sql/Sql/Server/Model/AzureSqlDeletedServerModel.cs Adds Location and ScheduledPurgeTime properties to the cmdlet model.
src/Sql/Sql/Server/Cmdlet/RestoreAzureSqlServer.cs Loosens RG-name validation when RG is not present in the deleted server model response.
src/Sql/Sql/Server/Cmdlet/GetAzSqlDeletedServer.cs Makes -Location optional and adds subscription-level list + client-side name filter behavior.
src/Sql/Sql/help/Get-AzSqlDeletedServer.md Updates syntax/description/examples for optional -Location and new output properties.
src/Sql/Sql/ChangeLog.md Documents the cmdlet behavior change and new output properties.
src/Sql/Sql.Test/UnitTests/AzureSqlDeletedServerAttributeTests.cs Updates unit test for Location no longer being mandatory.
src/Sql/Sql.Test/SessionRecords/.../TestRestoreNonExistentDeletedServer.json Updates recorded HTTP interactions consistent with SDK/api-version changes.
src/Sql/Sql.Test/ScenarioTests/DeletedServerTests.ps1 Adds new scenario tests for subscription-level listing and server-name-only filtering; updates existing location test expectations.
src/Sql/Sql.Test/ScenarioTests/DeletedServerTests.cs Wires up the new PowerShell scenario tests.
src/Sql/Sql.Management.Sdk/README.md Points AutoRest generation at newer SQL spec commit and the new deletedServers spec file path.
src/Sql/Sql.Management.Sdk/Generated/Models/ResourceAutoGenerated.cs New generated base model for ARM resources (used by updated deleted server model inheritance).
src/Sql/Sql.Management.Sdk/Generated/Models/ProxyResourceAutoGenerated.cs New generated proxy-resource base model (used by DeletedServer).
src/Sql/Sql.Management.Sdk/Generated/Models/DeletedServerProperties.cs Adds OriginalResourceGroup and ScheduledPurgeTime to deleted server properties.
src/Sql/Sql.Management.Sdk/Generated/Models/DeletedServer.cs Updates deleted server model inheritance and adds OriginalResourceGroup + ScheduledPurgeTime.
src/Sql/Sql.Management.Sdk/Generated/DeletedServersOperations.cs Updates api-version and adds subscription-scoped List operation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +115 to +119
string[] idSegments = deletedServer.Id?.Split('/');
string parsedSubscriptionId = idSegments?[2];
string parsedLocation = idSegments?[6]?.Replace(" ", "");

// Parse servername and subscription from originalId if available
string parsedServerName = segments[8];
string parsedSubscriptionId = segments[2];
string parsedResourceGroupName = segments[4];
// OriginalId format: /subscriptions/{sub}/resourceGroups/{rg}[4]/providers/Microsoft.Sql/servers/{name}
Comment on lines +80 to +82
return deletedServers
.Select(s => ModelAdapter.CreateDeletedServerModelFromResponse(s))
.Where(s => string.IsNullOrEmpty(this.ServerName) || s.ServerName == this.ServerName);
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
Successfully started running 3 pipeline(s).

Copilot AI review requested due to automatic review settings August 15, 2026 10:23
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines:
Successfully started running 3 pipeline(s).

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

Copilot reviewed 12 out of 26 changed files in this pull request and generated no new comments.

Suppressed comments (4)

src/Sql/Sql/Server/Services/AzureSqlDeletedServerCommunicator.cs:78

  • ListDeletedServersByLocation returns only the first page from the SDK (IPage). If the service paginates results, callers will miss deleted servers beyond the first page. Consider iterating NextPageLink (ListByLocationNext) to return the full set.
        public IEnumerable<Management.Sql.Models.DeletedServer> ListDeletedServersByLocation(string location, string subscriptionId = null)
        {
            return GetCurrentSqlClient(subscriptionId).DeletedServers.ListByLocation(location);
        }

src/Sql/Sql/Server/Services/AzureSqlDeletedServerCommunicator.cs:70

  • ListDeletedServers returns only the first page from the SDK (IPage). If the service paginates results, callers will miss deleted servers beyond the first page. Consider iterating NextPageLink (ListNext) to return the full set.

This issue also appears on line 75 of the same file.

        public IEnumerable<Management.Sql.Models.DeletedServer> ListDeletedServers(string subscriptionId = null)
        {
            return GetCurrentSqlClient(subscriptionId).DeletedServers.List();
        }

src/Sql/Sql/Server/Services/AzureSqlDeletedServerAdapter.cs:134

  • ResourceGroupName is now populated only from DeletedServer.OriginalResourceGroup. If the service response omits this property (but still includes OriginalId), ResourceGroupName becomes null, which can break restore validation (e.g., ResourceGroupMismatchForRestore) and reduces output completeness. Consider falling back to parsing the resource group from OriginalId when OriginalResourceGroup is empty.
                Location = parsedLocation,
                ScheduledPurgeTime = deletedServer.ScheduledPurgeTime,
                SubscriptionId = parsedSubscriptionId,
                ResourceGroupName = deletedServer.OriginalResourceGroup
            };

src/Sql/Sql/help/Get-AzSqlDeletedServer.md:21

  • The DESCRIPTION doesn’t mention the now-supported "-ServerName without -Location" scenario (client-side filter over the subscription-level list). Adding this helps users understand how -ServerName behaves when -Location is omitted.
The **Get-AzSqlDeletedServer** cmdlet returns information about one or more deleted Azure SQL servers in a subscription. Specify **-Location** to scope results to a region, or specify both **-Location** and **-ServerName** to retrieve a single deleted server.

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.

4 participants