Skip to content

Commit e920533

Browse files
author
Alexander (Sasha) Nosov
committed
Skip if LT=DR
1 parent de5129e commit e920533

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

samples/manage/azure-hybrid-benefit/modify-license-type/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services: Azure SQL
33
platforms: Azure
44
author: anosov1960,rodrigomonteiro-gbb
55
ms.author: sashan.romontei
6-
ms.date: 06/21/2025
6+
ms.date: 10/13/2025
77
---
88

99
# About this sample
@@ -22,12 +22,14 @@ ms.date: 06/21/2025
2222

2323
06/10/2025 - Fixed a RG filter for SQL DB
2424

25+
10/13/2025 - blocked modification of the DR replica
26+
2527

2628
# Overview
2729

2830
This script provides a scaleable solution to change the license type of various Azure SQL resources within the selected scope. It automates the process of modifying license settings for SQL Databases, Elastic Pools, SQL Managed Instances, SQL Instance Pools, SQL Virtual Machines, and DataFactory SSIS Integration Runtimes. The script supports targeting a single subscription, a list of subscriptions defined in a CSV file, or all accessible subscriptions. Optionally, it can also start resources that are stopped (if the -ForceStartOnResources parameter is enabled).
2931

30-
This script is designed to help administrators standardize SQL licensing across their Azure environment by automating license updates. It accepts a subscription ID or CSV file (for a list of subscriptions). If no subscription is specified, it defaults to updating resources in all accessible subscriptions.
32+
This script is designed to help administrators standardize SQL licensing across their Azure environment by automating license updates. It accepts a subscription ID or CSV file (for a list of subscriptions). If no subscription is specified, it defaults to updating resources in all accessible subscriptions. The update will preserve the existing configuration of the passive replicas with failover rights (with License type value set to "DR").
3133

3234
# Target Resource Types
3335

@@ -70,13 +72,14 @@ The scripts is seamlessly integrated with Azure Authentication. It uses managed
7072
|`-SubId`|`subscription_id` *or* a file_name|Optional: Subscription id or a .csv file with the list of subscriptions<sup>1</sup>. If not specified all subscriptions will be scanned|
7173
|`-ResourceGroup` |`resource_group_name`|Optional: Limits the scope to a specific resource group|
7274
|`-ResourceName` |`resource_name`|Optional: Limits the scope to resources associated with this name. For SQL Server - updates all databases under the specified server. For SQL Managed Instance - updates the specified instance. For SQL VM - updates the specified VM |
73-
|`-LicenseType` | `LicenseIncluded` (default) or `BasePrice` | Optional: Sets the license type to the specified value |
75+
|`-LicenseType` | `LicenseIncluded` (default) or `BasePrice` | Optional: Sets the license type to the specified value<sup>2</sup> |
7476
|`-ExclusionTags`| `'{"tag1":"value1","tag2":"value2"}'` |*Optional*. If specified, excludes the resources that have these tags assigned.|
7577
|`-TenantId`| `tenant_id` |*Optional*. If specified, uses this tenant id to log in. Otherwise, the current context is used.|
7678
|`-ReportOnly`| |*Optional*. If true, generates a csv file with the list of resources that are to be modified, but doesn't make the actual change.|
7779
|`-UseManagedIdentity`| |*Optional*. If true, logs in both PowerShell and CLI using managed identity. Required to run the script as a runbook.|
7880

7981
<sup>1</sup>You can generate a .csv file that lists only specific subscriptions. E.g., the following command will include only production subscriptions (exclude dev/test).
82+
<sup>2</sup>the
8083
```PowerShell
8184
$tenantId = "<your-tenant-id>"
8285
Get-AzSubscription -TenantId $tenantId | Where-Object {

samples/manage/azure-hybrid-benefit/modify-license-type/modify-azure-sql-license-type.ps1

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ foreach ($sub in $subscriptions) {
313313

314314

315315
if (-not $ReportOnly) {
316-
Write-Output "Updating SQL VM '$($sqlvm.name)' in RG '$($sqlvm.resourceGroup)' to license type '$SqlVmLicenseType'..."
317-
$result = az sql vm update -n $sqlvm.name -g $sqlvm.resourceGroup --license-type $SqlVmLicenseType -o json | ConvertFrom-Json
318-
$finalStatus += $result
316+
if ($sqlvm.sqlServerLicenseType -ne "DR") { #should not modify a DR replica
317+
Write-Output "Updating SQL VM '$($sqlvm.name)' in RG '$($sqlvm.resourceGroup)' to license type '$SqlVmLicenseType'..."
318+
$result = az sql vm update -n $sqlvm.name -g $sqlvm.resourceGroup --license-type $SqlVmLicenseType -o json | ConvertFrom-Json
319+
$finalStatus += $result
320+
}
319321
}
320322
}
321323
}
@@ -381,9 +383,11 @@ foreach ($sub in $subscriptions) {
381383
}
382384

383385
if (-not $ReportOnly) {
384-
Write-Output "Updating SQL Managed Instance '$($mi.name)' in RG '$($mi.resourceGroup)' to license type '$LicenseType'..."
385-
$result = az sql mi update --name $mi.name --resource-group $mi.resourceGroup --license-type $LicenseType -o json | ConvertFrom-Json
386-
$finalStatus += $result
386+
if ($mi.licenseType -ne "DR"){ #should not modify a DR replica
387+
Write-Output "Updating SQL Managed Instance '$($mi.name)' in RG '$($mi.resourceGroup)' to license type '$LicenseType'..."
388+
$result = az sql mi update --name $mi.name --resource-group $mi.resourceGroup --license-type $LicenseType -o json | ConvertFrom-Json
389+
$finalStatus += $result
390+
}
387391
}
388392
}
389393
}
@@ -660,9 +664,11 @@ foreach ($sub in $subscriptions) {
660664
Location = $pool.location
661665
}
662666
if (-not $ReportOnly) {
663-
Write-Output "Updating SQL Instance Pool '$($pool.name)' in RG '$($pool.resourceGroup)' to license type '$LicenseType'..."
664-
$result = az sql instance-pool update --name $pool.name --resource-group $pool.resourceGroup --license-type $LicenseType -o json | ConvertFrom-Json
665-
$finalStatus += $result
667+
if ($pool.licenseType -ne "DR"){ #should not modify a DR replica
668+
Write-Output "Updating SQL Instance Pool '$($pool.name)' in RG '$($pool.resourceGroup)' to license type '$LicenseType'..."
669+
$result = az sql instance-pool update --name $pool.name --resource-group $pool.resourceGroup --license-type $LicenseType -o json | ConvertFrom-Json
670+
$finalStatus += $result
671+
}
666672
}
667673
}
668674
}

0 commit comments

Comments
 (0)