You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Azure Runbook updates the license type for various Azure SQL resources using Azure CLI and PowerShell commands. 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 -Force_Start_On_Resources parameter is enabled).
12
-
13
-
This script is designed to help administrators standardize SQL licensing across their Azure environment by automating license updates. In summary, the script:
14
-
15
-
Targets Multiple Resource Types:
16
-
SQL Virtual Machines: Updates license types after checking if the VM is running. If not, it can optionally start the VM to perform the update.
17
-
SQL Managed Instances: Detects instances that are stopped or not in the "Ready" state and can force them to start before updating.
18
-
SQL Databases & Elastic Pools: Scans individual SQL servers to locate databases and elastic pools with a different license type and updates them accordingly.
19
-
SQL Instance Pools: Locates instance pools that require an update.
20
-
DataFactory SSIS Integration Runtimes: Checks for integration runtimes with an out-of-date license setting and updates them.
21
-
Flexible Subscription Targeting:
22
-
The script 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.
23
-
Interactive Reporting:
24
-
The script logs steps along the process and compiles a final report summarizing which resources were updated in each category.
25
-
Seamless Integration with Azure Authentication:
26
-
It uses managed identity authentication (via Connect-AzAccount -Identity and az login --identity) to connect to your Azure environment securely.
11
+
This Azure Runbook updates the license type for various Azure SQL resources using Azure CLI and PowerShell commands. 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).
12
+
13
+
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.
14
+
15
+
# Target Resource Types
16
+
17
+
- SQL Virtual Machines: Updates license types after checking if the VM is running. If not, it can optionally start the VM to perform the update.
18
+
- SQL Managed Instances: Detects instances that are stopped or not in the "Ready" state and can force them to start before updating.
19
+
- SQL Databases & Elastic Pools: Scans individual SQL servers to locate databases and elastic pools with a different license type and updates them accordingly.
20
+
- SQL Instance Pools: Locates instance pools that require an update.
21
+
- DataFactory SSIS Integration Runtimes: Checks for integration runtimes with an out-of-date license setting and updates them.
27
22
28
23
# Required Permissions
29
24
The automation account needs to have the bellow permissions in order to be able to successfully run the Runbook and update all the SQL Server resources license type:
@@ -34,65 +29,148 @@ The automation account needs to have the bellow permissions in order to be able
A *Subscription Contributor* role has sufficient permissions to mdify any of the above resources.
39
33
40
-
# Additional Information
34
+
# Interactive Reporting
35
+
36
+
The script logs steps along the process and compiles a final report summarizing which resources were updated in each category.
41
37
42
-
Script Parameters:
43
-
- SubId: A single subscription ID or the filename of a CSV file containing multiple subscriptions.
44
-
- ResourceGroup: (Optional) Limits the script’s operations to a specific resource group.
45
-
- LicenseType: (Optional) Defines the target license type. Valid values are "LicenseIncluded" (default) or "BasePrice".
46
-
- Force_Start_On_Resources: (Optional) When enabled, the script will attempt to start SQL VMs and SQL Managed Instances if they are not running before applying the update.
47
-
Logging & Error Handling:
38
+
# Integration with Azure Authentication
39
+
40
+
The scripts is seamlessly integrated with Azure Authentication. It uses managed identity authentication (via Connect-AzAccount -Identity and az login --identity) to connect to your Azure environment securely.
|-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|
48
+
|-ResourceGroup |resource_group_name|Optional: Limits the scope to a specific resource group|
49
+
|-LicenseType | "LicenseIncluded" (default) or "BasePrice" | Optional: Sets the license type to the specified value |
50
+
|-ForceStartOnResources||(Optional) When enabled, the script will attempt to start SQL VMs and SQL Managed Instances if they are not running before applying the update.|
51
+
52
+
# Logging & Error Handling
48
53
49
54
The script logs key actions to the console and captures error messages using Write-Error. Check the console output for a summary report detailing which resources were updated.
50
55
51
-
# Customizations:
56
+
# Customizations
57
+
52
58
You might want to customize the script’s logging or incorporate additional logging (e.g., writing to a file or Azure Log Analytics) to integrate seamlessly with your monitoring and reporting workflow.
53
59
54
-
# Creating an Azure Runbook
60
+
# Script execution examples
61
+
62
+
## Example 1
63
+
64
+
The following command will scan all the subscriptions to which the user has access to, and set the license type to pay-as-you-go on all SQL resources in each subscription that the user has access to.
The following command will scan the resource group `<resource_group_name>` in the subscription `<sub_id>`, set the license type value to pay-as-you-go. If the resource group has SQL VMs in the offline state, it will start each VM before applying the change, and then stop it.
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.
103
+
104
+
1. Launch the [Cloud Shell](https://shell.azure.com/). For details, [read more about PowerShell in Cloud Shell](https://aka.ms/pscloudshell/docs).
105
+
106
+
1. Connect to Azure AD. You must specify `<tenant_id>` if you have access to more than one AAD tenants.
107
+
108
+
```console
109
+
Connect-AzureAD -TenantID <tenant_id>
110
+
```
111
+
112
+
1. Upload the script to your cloud shell using the following command:
### 2. Create or Use an Existing Automation Account
66
-
[Create a new automation account](https://ms.portal.azure.com/#create/Microsoft.AutomationAccount) or open an existing one.
67
-
In the Advanced section, ensure that System assigned identity is selected.
136
+
[Create a new automation account](https://ms.portal.azure.com/#create/Microsoft.AutomationAccount) or open an existing one. In the Advanced section, ensure that System assigned identity is selected.
137
+
68
138
### 3. Import the Runbook
69
-
Navigate to the Process Automation group and select Runbooks.
70
-
Click on the Import a runbook tab and configure it:
71
-
File: Select the file you downloaded in Step 1.
72
-
Name: Enter a name for the runbook.
73
-
Type: Set to PowerShell.
74
-
Runtime Version: Choose 7.2.
75
-
Click Import.
139
+
- Navigate to the Process Automation group and select **Runbooks**.
140
+
141
+
- Click on the **Import a runbook** tab and configure it:
142
+
143
+
**File**: Select the file you downloaded in Step 1.
144
+
**Name**: Enter a name for the runbook.
145
+
**Type**: Set to PowerShell.
146
+
**Runtime Version**: Choose 7.2.
147
+
148
+
- Click **Import**.
149
+
76
150
### 4. Publish the Runbook
77
-
After the runbook is imported, click the Publish button to make it available for scheduling.
151
+
After the runbook is imported, click the **Publish** button to make it available for scheduling.
78
152
79
153
### 5. Link the Runbook to a Schedule
80
-
Once the runbook status is Published, click on the Link to schedule button.
81
-
Select Link a schedule to your runbook and click + Add a schedule.
82
-
Configure the schedule:
83
-
Name: Provide a name for the schedule.
84
-
Start Time: Set the desired start time.
85
-
Recurrence: Choose the recurrence need it.
86
-
Click Create.
154
+
155
+
- Once the runbook status is *Published*, click on the **Link to schedule** button.
156
+
- Select *Link a schedule to your runbook* and click **+ Add**.
157
+
- Configure the schedule:
158
+
**Name**: Provide a name for the schedule.
159
+
**Start Time**: Set the desired start time.
160
+
**Recurrence**: Choose the recurrence need it.
161
+
- Click **Create**.
162
+
87
163
### 6. Configure Runbook Parameters
88
-
Return to the Schedule runbook page.
89
-
Click on Parameters and run settings.
90
-
Paste the license ID value into the appropriate field.
91
-
Click OK to link the schedule, then OK again to create the job.
164
+
- Return to the **Schedule runbook** page.
165
+
- Click on **Parameters** and run settings.
166
+
- Paste the license type value into the appropriate field.
167
+
- Click **OK** to link the schedule, then **OK** again to create the job.
168
+
92
169
### 7. Verify the Runbook Execution
93
-
On the runbook Overview page, open a recent job that was completed after the scheduled start time.
94
-
Click on the Output tab and verify that you see:
95
-
Properties.activationState=Activated
170
+
On the runbook Overview page:
171
+
- Open a recent job that was completed after the scheduled start time.
172
+
- Click on the **Output tab** and verify that you see: `Properties.activationState=Activated `
173
+
96
174
Your license is now active.
97
175
98
176
For more information about the runbooks, see the [Runbook tutorial](https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-powershell)
Copy file name to clipboardExpand all lines: samples/manage/azure-hybrid-benefit/modify-license-type/modify-license-type.ps1
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ CSV List of Subscriptions:
12
12
Process multiple subscriptions provided in a CSV file.
13
13
All Accessible Subscriptions:
14
14
Automatically detect and update all subscriptions that you have access to.
15
-
For specific resource types like SQL Virtual Machines and SQL Managed Instances, the script can optionally start the resource if it is in a stopped state (when the -Force_Start_On_Resources parameter is enabled) before applying the license update.
15
+
For specific resource types like SQL Virtual Machines and SQL Managed Instances, the script can optionally start the resource if it is in a stopped state (when the -ForceStartOnResources parameter is enabled) before applying the license update.
16
16
17
17
The script processes several types of Azure SQL resources including:
18
18
@@ -33,7 +33,7 @@ This automation helps ensure that your licensing configuration is consistent acr
33
33
.PARAMETERLicenseType
34
34
Optional. License type to set. Allowed values: "LicenseIncluded" (default) or "BasePrice".
35
35
36
-
.PARAMETERForce_Start_On_Resources
36
+
.PARAMETERForceStartOnResources
37
37
Optional. If true, starts SQL VMs and SQL Managed Instances before updating their license type.
38
38
#>
39
39
@@ -49,7 +49,7 @@ param (
49
49
[string] $LicenseType="LicenseIncluded",
50
50
51
51
[Parameter(Mandatory=$false)]
52
-
[bool] $Force_Start_On_Resources=$false
52
+
[bool] $ForceStartOnResources=$false
53
53
)
54
54
55
55
# Suppress unnecessary logging output
@@ -198,7 +198,7 @@ foreach ($sub in $subscriptions) {
198
198
$report["SQLVMUpdated"] +=$sqlvm.name
199
199
}
200
200
else {
201
-
if ($Force_Start_On_Resources) {
201
+
if ($ForceStartOnResources) {
202
202
Write-Output"SQL VM '$($sqlvm.name)' is not running. Forcing start to update license..."
203
203
az vm start --resource-group $sqlvm.resourceGroup--name $sqlvm.name--no-wait yes
204
204
$sqlVmsToUpdate.Add($sqlvm) |Out-Null
@@ -213,7 +213,7 @@ foreach ($sub in $subscriptions) {
0 commit comments