Update GetAzSqlDeletedServer command - #30016
Conversation
… and add output properties
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
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-AzSqlDeletedServerlogic to use it when-Locationis omitted. - Extended the deleted server output model with
ScheduledPurgeTimeandLocation, 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.
| 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} |
| return deletedServers | ||
| .Select(s => ModelAdapter.CreateDeletedServerModelFromResponse(s)) | ||
| .Where(s => string.IsNullOrEmpty(this.ServerName) || s.ServerName == this.ServerName); |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
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.
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
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
[x ] Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.