Skip to content

Commit db3721d

Browse files
authored
Modified readme
1 parent 9e644ac commit db3721d

2 files changed

Lines changed: 134 additions & 56 deletions

File tree

samples/manage/azure-hybrid-benefit/modify-license-type/README.md

Lines changed: 129 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@ ms.date: 04/08/2025
88

99
# Overview
1010

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 -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.
2722

2823
# Required Permissions
2924
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
3429
1. **Data Factory Contributor**: *Data Factory Contributor role*.
3530
1. **Virtual Machine Contributor**: *Virtual Machine Contributor role*.
3631

37-
3832
A *Subscription Contributor* role has sufficient permissions to mdify any of the above resources.
3933

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.
4137

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.
41+
42+
# Script parameters
43+
44+
45+
| **Parameter**                                         | **Value**                                                                       | **Description** |
46+
|:--|:--|:--|
47+
|-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
4853

4954
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.
5055

51-
# Customizations:
56+
# Customizations
57+
5258
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.
5359

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.
65+
66+
```PowerShell
67+
.\modify-license-type.ps1 -LicenseType LicenseIncluded
68+
```
69+
70+
## Example 2
71+
72+
The following command will scan a specific subscription, and set the license type to pay-as-you-go on all SQL resources.
73+
74+
```PowerShell
75+
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType LicenseIncluded
76+
```
77+
78+
## Example 3
79+
80+
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.
81+
82+
```PowerShell
83+
.\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType LicenseIncluded -ForceStartOnResources
84+
```
85+
86+
# Running the script from your PC
87+
88+
1. Connect to Azure AD. You must specify `<tenant_id>` if you have access to more than one AAD tenants.
89+
90+
```console
91+
Connect-AzureAD -TenantID <tenant_id>
92+
```
93+
1. Open a command shell on your device and download the script the script to your local folder.
94+
95+
```console
96+
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/refs/heads/master/samples/manage/azure-hybrid-benefit/modify-license-type/modify-license-type.ps1
97+
```
98+
1. Execute the command as shown by the examples
99+
100+
# Running the script using Cloud Shell
101+
102+
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:
113+
114+
```console
115+
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/refs/heads/master/samples/manage/azure-hybrid-benefit/modify-license-type/modify-license-type.ps1
116+
```
117+
118+
1. Execute the command as shown by the examples.
119+
120+
> [!NOTE]
121+
> - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on MacOS.
122+
> - The script will be uploaded directly to the home folder associated with your Cloud Shell session.
123+
124+
# Schedule the script execution using Azure Runbook
55125

56126
You can schedule the command to run as a runbook. Follow these steps using the Azure Portal:
57127

58128
### 1. Download the Script
59129

60-
Open a command shell on your device and run the command below. This will copy the script to your local folder.
130+
Open a command shell on your device and dowload the script to to your current folder.
61131

62132
```console
63133
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/refs/heads/master/samples/manage/azure-hybrid-benefit/modify-license-type/modify-license-type.ps1
64134
```
65135
### 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+
68138
### 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+
76150
### 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.
78152

79153
### 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+
87163
### 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+
92169
### 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+
96174
Your license is now active.
97175

98176
For more information about the runbooks, see the [Runbook tutorial](https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-powershell)

samples/manage/azure-hybrid-benefit/modify-license-type/modify-license-type.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CSV List of Subscriptions:
1212
Process multiple subscriptions provided in a CSV file.
1313
All Accessible Subscriptions:
1414
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.
1616
1717
The script processes several types of Azure SQL resources including:
1818
@@ -33,7 +33,7 @@ This automation helps ensure that your licensing configuration is consistent acr
3333
.PARAMETER LicenseType
3434
Optional. License type to set. Allowed values: "LicenseIncluded" (default) or "BasePrice".
3535
36-
.PARAMETER Force_Start_On_Resources
36+
.PARAMETER ForceStartOnResources
3737
Optional. If true, starts SQL VMs and SQL Managed Instances before updating their license type.
3838
#>
3939

@@ -49,7 +49,7 @@ param (
4949
[string] $LicenseType = "LicenseIncluded",
5050

5151
[Parameter(Mandatory = $false)]
52-
[bool] $Force_Start_On_Resources = $false
52+
[bool] $ForceStartOnResources = $false
5353
)
5454

5555
# Suppress unnecessary logging output
@@ -198,7 +198,7 @@ foreach ($sub in $subscriptions) {
198198
$report["SQLVMUpdated"] += $sqlvm.name
199199
}
200200
else {
201-
if ($Force_Start_On_Resources) {
201+
if ($ForceStartOnResources) {
202202
Write-Output "SQL VM '$($sqlvm.name)' is not running. Forcing start to update license..."
203203
az vm start --resource-group $sqlvm.resourceGroup --name $sqlvm.name --no-wait yes
204204
$sqlVmsToUpdate.Add($sqlvm) | Out-Null
@@ -213,7 +213,7 @@ foreach ($sub in $subscriptions) {
213213
# --- Section: Update SQL Managed Instances (Stopped then Ready) ---
214214
$sqlMIsToUpdate = [System.Collections.ArrayList]::new()
215215
try {
216-
if ($Force_Start_On_Resources) {
216+
if ($ForceStartOnResources) {
217217
Write-Output "Seeking SQL Managed Instances that are stopped and require an update..."
218218
$miQuery = if ($rgFilter) {
219219
"[?licenseType!='${LicenseType}' && state!='Ready' && $rgFilter].{Name:name, State:state, ResourceGroup:resourceGroup}"

0 commit comments

Comments
 (0)