mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Added Recurring consent to modify-license-type
This commit is contained in:
@@ -3,7 +3,7 @@ services: Azure Arc-enabled SQL Server
|
||||
platforms: Azure
|
||||
author: anosov1960
|
||||
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** |
|
||||
|:--|:--|:--|
|
||||
|-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|
|
||||
|-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 |
|
||||
|-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"|
|
||||
|-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|
|
||||
|`-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|
|
||||
|`-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 |
|
||||
|`-ConsentToRecurringPayg` | "Yes" or "No" |*Optional*. Consents to enabling the recurring PAYG billing. LicenseType must be "PAYG". Applies to CSP subscriptions only.|
|
||||
|`-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"|
|
||||
|`-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.
|
||||
```PowerShell
|
||||
@@ -66,7 +67,7 @@ The following command will scan resource group `<resource_group_name>` in the su
|
||||
|
||||
## 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
|
||||
.\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
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
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.
|
||||
|
||||
+19
-2
@@ -12,6 +12,7 @@
|
||||
# -ResourceGroup [resource_goup] (Optional. Limits the scope to a specific resoure group)
|
||||
# -MachineName [machine_name] (Optional. Limits the scope to a specific machine)
|
||||
# -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"
|
||||
# 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"
|
||||
@@ -34,6 +35,8 @@ param (
|
||||
[Parameter (Mandatory= $false)]
|
||||
[ValidateSet("PAYG","Paid","LicenseOnly", IgnoreCase=$false)]
|
||||
[string] $LicenseType,
|
||||
[ValidateSet("Yes","No", IgnoreCase=$false)]
|
||||
[string] $ConsentToRecurringPayg,
|
||||
[Parameter (Mandatory= $false)]
|
||||
[ValidateSet("Yes","No", IgnoreCase=$false)]
|
||||
[string] $UsePcoreLicense,
|
||||
@@ -234,8 +237,7 @@ foreach ($sub in $subscriptions){
|
||||
$settings["LicenseType"] = $LicenseType
|
||||
$WriteSettings = $true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
# 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"
|
||||
}
|
||||
}
|
||||
|
||||
# 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) {
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user