Skip to content

Commit b31c28a

Browse files
authored
updated modify-license-type to support PAYG-R consent
1 parent 79e88a9 commit b31c28a

2 files changed

Lines changed: 47 additions & 17 deletions

File tree

samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services: Azure Arc-enabled SQL Server
33
platforms: Azure
44
author: anosov1960
55
ms.author: sashan
6-
ms.date: 12/01/2024
6+
ms.date: 05/01/2025
77
---
88

99

@@ -16,42 +16,45 @@ If not specified, all subscriptions your role has access to are scanned.
1616

1717
# Prerequisites
1818

19-
- You must have at least *Azure Connected Machine Resource Administrator* role and subscription *Reader* role.
19+
- You must have at least a *Azure Connected Machine Resource Administrator* role in each subscription you modify.
2020
- The Azure extension for SQL Server is updated to version 1.1.2230.58 or newer.
2121
- You must be connected to Azure AD and logged in to your Azure account. If your account have access to multiple tenants, make sure to log in with a specific tenant ID.
2222

23+
2324
# Launching the script
2425

2526
The script accepts the following command line parameters:
2627

2728
| **Parameter**                                         | **Value**                                                                       | **Description** |
2829
|:--|:--|:--|
29-
|-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|
30-
|-ResourceGroup |resource_group_name|Optional: Limits the scope to a specific resource group|
31-
|-MachineName |machine_name|Optional: Limits the scope to a specific machine|
32-
|-LicenseType | "Paid", "PAYG" or "LicenseOnly"| Optional: Sets the license type to the specified value |
33-
|-UsePcoreLicense | "Yes", "No" | Optional. Enables unlimited virtualization license if the value is "Yes" or disables it if the value is "No". To enable, the license type must be "Paid" or "PAYG"|
34-
|-EnableESU | "Yes", "No" | Optional. Enables the ESU policy the value is "Yes" or disables it if the value is "No". To enable, the license type must be "Paid" or "PAYG"|
35-
|-Force| |Optional. Forces the change of the license type to the specified value on all installed extensions. If -Force is not specified, the -LicenseType value is set only if undefined. Ignored if -LicenseType is not specified|
30+
|`-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|
31+
|`-ResourceGroup` |resource_group_name|*Optional*: Limits the scope to a specific resource group|
32+
|`-MachineName` |machine_name|*Optional*: Limits the scope to a specific machine|
33+
|`-LicenseType` | "Paid", "PAYG" or "LicenseOnly"| *Optional*: Sets the license type to the specified value |
34+
|`-ConsentToRecurringPAYG` | "Yes" or "No" |*Optional*. Consents to enabling the recurring PAYG billing. LicenseType must be "PAYG". Applies to CSP subscriptions only.|
35+
|`-UsePcoreLicense` | "Yes", "No" | *Optional*. Enables unlimited virtualization license if the value is "Yes" or disables it if the value is "No". To enable, the license type must be "Paid" or "PAYG"|
36+
|`-EnableESU` | "Yes", "No" | *Optional*. Enables the ESU policy the value is "Yes" or disables it if the value is "No". To enable, the license type must be "Paid" or "PAYG"|
37+
|`-Force`| |*Optional*. Forces the change of the license type to the specified value on all installed extensions. If `-Force` is not specified, the `-LicenseType` value is set only if undefined. Ignored if `-LicenseType` is not specified|
3638

3739
<sup>1</sup>You can create a .csv file using the following command and then edit to remove the subscriptions you don't want to scan.
3840
```PowerShell
3941
Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation
4042
```
43+
4144
## Example 1
4245

43-
The following command will scan all the subscriptions to which the user has access to, and set the license type to "PAYG" on all servers where license type is undefined.
46+
The following command will scan all the subscriptions to which the user has access to, and set the license type to "Paid" on all servers where license type is undefined.
4447

4548
```PowerShell
46-
.\modify-license-type.ps1 -LicenseType PAYG
49+
.\modify-license-type.ps1 -LicenseType Paid
4750
```
4851

4952
## Example 2
5053

51-
The following command will scan all all the subscriptions to which the user has access to, and set the license type to "PAYG" on all servers .
54+
The following command will scan the subscription `<sub_id>` and set the license type value to "Paid" on all servers.
5255

5356
```PowerShell
54-
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType PAYG -Force
57+
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType Paid -Force
5558
```
5659

5760
## Example 3
@@ -64,7 +67,7 @@ The following command will scan resource group `<resource_group_name>` in the su
6467

6568
## Example 4
6669

67-
The following command will set License Type to 'Paid" and enables ESU on all servers in the subscriptions `<sub_id>` and the resource group `<resource_group_name>`.
70+
The following command will set License Type to "Paid" and enables ESU on all servers in the subscriptions `<sub_id>` and the resource group `<resource_group_name>`.
6871

6972
```console
7073
.\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType Paid -EnableESU Yes -Force
@@ -78,6 +81,16 @@ The following command will disable ESU on all servers in the subscriptions `<sub
7881
.\modify-license-type.ps1 -SubId <sub_id> -EnableESU No
7982
```
8083

84+
## Example 6
85+
86+
The following command will scan all subscriptions in the account, set the license type value to "PAYG" and consents to enabling recurring billing on all servers in the account.
87+
88+
```PowerShell
89+
.\modify-license-type.ps1 -LicenseType PAYG -ConsentToRecurringPAYG Yes -Force
90+
```
91+
> [!NOTE]
92+
> The recurring billing only supported in the CSP accounts.
93+
8194
# Running the script using Cloud Shell
8295

8396
This option is recommended because Cloud shell has the Azure PowerShell modules pre-installed and you are automatically authenticated. Use the following steps to run the script in Cloud Shell.

samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# -ResourceGroup [resource_goup] (Optional. Limits the scope to a specific resoure group)
1313
# -MachineName [machine_name] (Optional. Limits the scope to a specific machine)
1414
# -LicenseType [license_type_value] (Optional. Sets the license type to the specified value)
15+
# -ConsentToRecurringPAYG [Yes or No] (Optional. Consents to enabling the recurring PAYG billing. LicenseType must be "PAYG". Applies to CSP subscriptions only.
1516
# -UsePcoreLicense [Yes or No] (Optional. Enables unlimited virtualization license if the value is "Yes" or disables it if the value is "No"
1617
# To enable, the license type must be "Paid" or "PAYG"
1718
# -EnableESU [Yes or No] (Optional. Enables the ESU policy if the value is "Yes" or disables it if the value is "No"
@@ -34,6 +35,8 @@ param (
3435
[Parameter (Mandatory= $false)]
3536
[ValidateSet("PAYG","Paid","LicenseOnly", IgnoreCase=$false)]
3637
[string] $LicenseType,
38+
[ValidateSet("Yes","No", IgnoreCase=$false)]
39+
[string] $ConsentToRecurringPAYG,
3740
[Parameter (Mandatory= $false)]
3841
[ValidateSet("Yes","No", IgnoreCase=$false)]
3942
[string] $UsePcoreLicense,
@@ -234,8 +237,7 @@ foreach ($sub in $subscriptions){
234237
$settings["LicenseType"] = $LicenseType
235238
$WriteSettings = $true
236239
}
237-
}
238-
240+
}
239241
}
240242

241243
# Enable ESU for qualified license types or disable
@@ -261,6 +263,21 @@ foreach ($sub in $subscriptions){
261263
write-host "The configured license type does not support ESUs"
262264
}
263265
}
266+
267+
# Add or update ConsentToRecurringPAYG setting if applicable
268+
if ($ConsentToRecurringPAYG -eq "Yes") {
269+
$isPayg = ($LicenseType -eq "PAYG") -or ($settings["LicenseType"] -eq "PAYG")
270+
if ($isPayg) {
271+
if (-not $settings.ContainsKey("ConsentToRecurringPAYG") -or -not $settings["ConsentToRecurringPAYG"]["Consented"]) {
272+
$settings["ConsentToRecurringPAYG"] = @{
273+
"Consented" = $true;
274+
"ConsentTimestamp" = [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
275+
}
276+
$WriteSettings = $true
277+
}
278+
}
279+
}
280+
264281
If ($WriteSettings) {
265282

266283
try {
@@ -275,4 +292,4 @@ foreach ($sub in $subscriptions){
275292
}
276293
}
277294

278-
295+

0 commit comments

Comments
 (0)