Added Recurring consent to modify-license-type

This commit is contained in:
Alexander (Sasha) Nosov
2025-05-01 16:51:28 -07:00
committed by GitHub
parent 5439d21259
commit 743cff4da6
5 changed files with 39 additions and 11 deletions
@@ -3,7 +3,7 @@ services: Azure Arc-enabled SQL Server
platforms: Azure platforms: Azure
author: anosov1960 author: anosov1960
ms.author: sashan ms.author: sashan
ms.date: 12/01/2024 ms.date: 05/01/2025
--- ---
@@ -27,13 +27,14 @@ The script accepts the following command line parameters:
| **Parameter**                                         | **Value**                                                                       | **Description** | | **Parameter**                                         | **Value**                                                                       | **Description** |
|:--|:--|:--| |:--|:--|:--|
|-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| |`-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|
|-ResourceGroup |resource_group_name|Optional: Limits the scope to a specific resource group| |`-ResourceGroup` |resource_group_name|*Optional*: Limits the scope to a specific resource group|
|-MachineName |machine_name|Optional: Limits the scope to a specific machine| |`-MachineName` |machine_name|*Optional*: Limits the scope to a specific machine|
|-LicenseType | "Paid", "PAYG" or "LicenseOnly"| Optional: Sets the license type to the specified value | |`-LicenseType` | "Paid", "PAYG" or "LicenseOnly"| *Optional*: Sets the license type to the specified value |
|-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"| |`-ConsentToRecurringPayg` | "Yes" or "No" |*Optional*. Consents to enabling the recurring PAYG billing. LicenseType must be "PAYG". Applies to CSP subscriptions only.|
|-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"| |`-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"|
|-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| |`-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"|
|`-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|
<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. <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.
```PowerShell ```PowerShell
@@ -66,7 +67,7 @@ The following command will scan resource group `<resource_group_name>` in the su
## Example 4 ## Example 4
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>`. 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>`.
```console ```console
.\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType Paid -EnableESU Yes -Force .\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType Paid -EnableESU Yes -Force
@@ -80,6 +81,16 @@ The following command will disable ESU on all servers in the subscriptions `<sub
.\modify-license-type.ps1 -SubId <sub_id> -EnableESU No .\modify-license-type.ps1 -SubId <sub_id> -EnableESU No
``` ```
## Example 6
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.
```PowerShell
.\modify-license-type.ps1 -LicenseType PAYG -ConsentToRecurringPayg Yes -Force
```
> [!NOTE]
> The recurring billing only supported in the CSP accounts.
# Running the script using Cloud Shell # Running the script using Cloud Shell
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. 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.
@@ -12,6 +12,7 @@
# -ResourceGroup [resource_goup] (Optional. Limits the scope to a specific resoure group) # -ResourceGroup [resource_goup] (Optional. Limits the scope to a specific resoure group)
# -MachineName [machine_name] (Optional. Limits the scope to a specific machine) # -MachineName [machine_name] (Optional. Limits the scope to a specific machine)
# -LicenseType [license_type_value] (Optional. Sets the license type to the specified value) # -LicenseType [license_type_value] (Optional. Sets the license type to the specified value)
# -ConsentToRecurringPayg [Yes or No] (Optional. Consents to enabling the recurring PAYG billing. LicenseType must be "PAYG". Applies to CSP subscriptions only.
# -UsePcoreLicense [Yes or No] (Optional. Enables unlimited virtualization license if the value is "Yes" or disables it if the value is "No" # -UsePcoreLicense [Yes or 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" # To enable, the license type must be "Paid" or "PAYG"
# -EnableESU [Yes or No] (Optional. Enables the ESU policy if the value is "Yes" or disables it if the value is "No" # -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 (
[Parameter (Mandatory= $false)] [Parameter (Mandatory= $false)]
[ValidateSet("PAYG","Paid","LicenseOnly", IgnoreCase=$false)] [ValidateSet("PAYG","Paid","LicenseOnly", IgnoreCase=$false)]
[string] $LicenseType, [string] $LicenseType,
[ValidateSet("Yes","No", IgnoreCase=$false)]
[string] $ConsentToRecurringPayg,
[Parameter (Mandatory= $false)] [Parameter (Mandatory= $false)]
[ValidateSet("Yes","No", IgnoreCase=$false)] [ValidateSet("Yes","No", IgnoreCase=$false)]
[string] $UsePcoreLicense, [string] $UsePcoreLicense,
@@ -234,8 +237,7 @@ foreach ($sub in $subscriptions){
$settings["LicenseType"] = $LicenseType $settings["LicenseType"] = $LicenseType
$WriteSettings = $true $WriteSettings = $true
} }
} }
} }
# Enable ESU for qualified license types or disable # Enable ESU for qualified license types or disable
@@ -261,6 +263,21 @@ foreach ($sub in $subscriptions){
write-host "The configured license type does not support ESUs" write-host "The configured license type does not support ESUs"
} }
} }
# Add or update ConsentToRecurringPayg setting if applicable
if ($ConsentToRecurringPayg -eq "Yes") {
$isPayg = ($LicenseType -eq "PAYG") -or ($settings["LicenseType"] -eq "PAYG")
if ($isPayg) {
if (-not $settings.ContainsKey("ConsentToRecurringPayg") -or -not $settings["ConsentToRecurringPayg"]["IsApplied"]) {
$settings["ConsentToRecurringPayg"] = @{
"IsApplied" = $true;
"LastUpdatedTimestamp" = [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
}
$WriteSettings = $true
}
}
}
If ($WriteSettings) { If ($WriteSettings) {
try { try {