mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
updated modify-license-type to support PAYG-R consent
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
|
||||
---
|
||||
|
||||
|
||||
@@ -16,42 +16,45 @@ If not specified, all subscriptions your role has access to are scanned.
|
||||
|
||||
# Prerequisites
|
||||
|
||||
- You must have at least *Azure Connected Machine Resource Administrator* role and subscription *Reader* role.
|
||||
- You must have at least a *Azure Connected Machine Resource Administrator* role in each subscription you modify.
|
||||
- The Azure extension for SQL Server is updated to version 1.1.2230.58 or newer.
|
||||
- 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.
|
||||
|
||||
|
||||
# Launching the script
|
||||
|
||||
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
|
||||
Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation
|
||||
```
|
||||
|
||||
## Example 1
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
```PowerShell
|
||||
.\modify-license-type.ps1 -LicenseType PAYG
|
||||
.\modify-license-type.ps1 -LicenseType Paid
|
||||
```
|
||||
|
||||
## Example 2
|
||||
|
||||
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 .
|
||||
The following command will scan the subscription `<sub_id>` and set the license type value to "Paid" on all servers.
|
||||
|
||||
```PowerShell
|
||||
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType PAYG -Force
|
||||
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType Paid -Force
|
||||
```
|
||||
|
||||
## Example 3
|
||||
@@ -64,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
|
||||
@@ -78,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.
|
||||
|
||||
+20
-3
@@ -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"]["Consented"]) {
|
||||
$settings["ConsentToRecurringPAYG"] = @{
|
||||
"Consented" = $true;
|
||||
"ConsentTimestamp" = [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
|
||||
}
|
||||
$WriteSettings = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
If ($WriteSettings) {
|
||||
|
||||
try {
|
||||
@@ -275,4 +292,4 @@ foreach ($sub in $subscriptions){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user