Skip to content

Commit 7637f45

Browse files
author
Alexander (Sasha) Nosov
committed
Modified readme files
1 parent b1ec280 commit 7637f45

4 files changed

Lines changed: 94 additions & 125 deletions

File tree

samples/manage/azure-arc-enabled-sql-server/modify-license-type/README.md

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The script accepts the following command line parameters:
5151
|`-ExclusionTags`| `{"name":"value","name":"value"}` |*Optional*. If specified, excludes the resources that have this tag assigned.|
5252
|`-TenantId`| `tenant_id` |*Optional*. If specified, uses this tenant id to log in. Otherwise, the current context is used.|
5353
|`-ReportOnly`| |*Optional*. If true, generates a csv file with the list of resources that are to be modified, but doesn't make the actual change.|
54-
|`-UseManagedIdentity`| |*Optional*. If true, logs in both PoaerShell and CLI using managed identity. Required to run the script as a runbook.|
54+
|`-UseManagedIdentity`| |*Optional*. If true, logs in both PowerShell and CLI using managed identity. Required to run the script as a runbook.|
5555

5656
<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.
5757
```PowerShell
@@ -65,52 +65,54 @@ Get-AzSubscription | Export-Csv .\mysubscriptions.csv -NoTypeInformation
6565
"Prod3"
6666
```
6767

68+
# Script execution examples
69+
6870
## Example 1
6971

70-
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, except those with the tag `Environment:Dev`
72+
The following command will scan all the subscriptions in tenant `<tenant_id>`, and list the machines that would have the license type change to "PAYG" on all servers where license type is undefined.
7173

7274
```PowerShell
73-
.\modify-license-type.ps1 -LicenseType PAYG -ExclusionTags {"Environment":"Dev"}
75+
.\modify-arc-sql-license-type.ps1 -TenantId <tenant_id> -LicenseType PAYG -ReportOnly
7476
```
7577

7678
## Example 2
7779

78-
The following command will scan the subscription `<sub_id>` and set the license type value to "Paid" on all servers listed in `machines.csv`.
80+
The following command will scan the subscription `<sub_id>` in the current tenant and set the license type value to "Paid" on all servers listed in `machines.csv`.
7981

8082
```PowerShell
81-
.\modify-license-type.ps1 -SubId <sub_id> -MachineName machines.csv -LicenseType Paid -Force
83+
.\modify-arc-sql-license-type.ps1 -SubId <sub_id> -MachineName machines.csv -LicenseType Paid -Force
8284
```
8385

8486
## Example 3
8587

86-
The following command will scan resource group `<resource_group_name>` in the subscription `<sub_id>`, set the license type value to "PAYG" and enable unlimited virtualization license on all servers in the specified resource group.
88+
The following command will scan resource group `<resource_group_name>` in the subscription `<sub_id>` within the current tenant, set the license type value to "PAYG" and enable unlimited virtualization license on all servers in the specified resource group.
8789

8890
```PowerShell
89-
.\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType PAYG -UsePcoreLicense Yes -Force
91+
.\modify-arc-sql-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType PAYG -UsePcoreLicense Yes -Force
9092
```
9193

9294
## Example 4
9395

94-
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>`.
96+
The following command will set License Type to "Paid" and enables ESU on all servers in the subscriptions `<sub_id>` of tenant `<tenant_id>` and the resource group `<resource_group_name>` except those with the tag `Environment:Dev`
9597

9698
```console
97-
.\modify-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType Paid -EnableESU Yes -Force
99+
.\modify-arc-sql-license-type.ps1 -TenantId <tenant_id> -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType Paid -EnableESU Yes -Force -ExclusionTags {"Environment":"Dev"}
98100
```
99101

100102
## Example 5
101103

102104
The following command will disable ESU on all servers in the subscriptions `<sub_id>`.
103105

104106
```console
105-
.\modify-license-type.ps1 -SubId <sub_id> -EnableESU No
107+
.\modify-arc-sql-license-type.ps1 -SubId <sub_id> -EnableESU No
106108
```
107109

108110
## Example 6
109111

110-
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.
112+
The following command will scan all subscriptions in the account using managed identity, set the license type value to "PAYG" and consents to enabling recurring billing on all servers in the account.
111113

112114
```PowerShell
113-
.\modify-license-type.ps1 -LicenseType PAYG -ConsentToRecurringPAYG Yes -Force
115+
.\modify-arc-sql-license-type.ps1 -LicenseType PAYG -ConsentToRecurringPAYG Yes -Force -UseManagedIdentity
114116
```
115117
> [!NOTE]
116118
> The recurring billing only supported in the CSP accounts.
@@ -121,7 +123,7 @@ This option is recommended because Cloud shell has the Azure PowerShell modules
121123

122124
1. Launch the [Cloud Shell](https://shell.azure.com/). For details, [read more about PowerShell in Cloud Shell](https://aka.ms/pscloudshell/docs).
123125

124-
1. Connect to Azure AD. You must specify `<tenant_id>` if you have access to more than one AAD tenants.
126+
1. Connect to Azure AD. You can skip this step if you specify `<tenant_id>` as a parameter of the script.
125127

126128
```console
127129
Connect-AzureAD -TenantID <tenant_id>
@@ -130,7 +132,7 @@ This option is recommended because Cloud shell has the Azure PowerShell modules
130132
1. Upload the script to your cloud shell using the following command:
131133

132134
```console
133-
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 -o modify-license-type.ps1
135+
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-arc-sql-license-type/modify-arc-sql-license-type.ps1 -o modify-arc-sql-license-type.ps1
134136
```
135137

136138
1. Run the script.
@@ -147,27 +149,13 @@ Use the following steps to run the script in a PowerShell session on your PC.
147149
1. Copy the script to your current folder:
148150

149151
```console
150-
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-license-type.ps1 -o modify-license-type.ps1
151-
```
152-
153-
1. Make sure the NuGet package provider is installed:
154-
155-
```console
156-
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
157-
Install-packageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Scope CurrentUser -Force
158-
```
159-
160-
1. Make sure the the Az module is installed. For more information, see [Install the Azure Az PowerShell module](https://learn.microsoft.com/powershell/azure/install-az-ps):
161-
162-
```console
163-
Install-Module Az -Scope CurrentUser -Repository PSGallery -Force
152+
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-arc-sql-license-type/modify-arc-sql-license-type.ps1 -o modify-arc-sql-license-type.ps1
164153
```
165154

166-
1. Connect to Azure AD and log in to your Azure account. You must specify `<tenant_id>` if you have access to more than one AAD tenants.
155+
1. Connect to Azure AD. You can skip this step if you specify `<tenant_id>` as a parameter of the script.
167156

168157
```console
169158
Connect-AzureAD -TenantID <tenant_id>
170-
Connect-AzAccount -TenantID (Get-AzureADTenantDetail).ObjectId
171159
```
172160

173-
1. Run the script.
161+
1. Run the script by following an appropriate example.

samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-arc-sql-license-type.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ if ($UseManagedIdentity) {
154154

155155
# Ensure the required modules are imported
156156

157+
158+
# Ensure NuGet provider is available
159+
if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
160+
Install-PackageProvider -Name NuGet -Force
161+
}
162+
163+
# Check if Az module is installed
164+
$installedModule = Get-InstalledModule -Name Az -ErrorAction SilentlyContinue
165+
166+
if (-not $installedModule) {
167+
Write-Host "Az module not found. Installing latest version..."
168+
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
169+
} else {
170+
# Get the latest version available in the PSGallery
171+
$latestVersion = (Find-Module -Name Az -Repository PSGallery).Version
172+
if ($installedModule.Version -lt $latestVersion) {
173+
Write-Host "Az module is outdated. Updating to latest version..."
174+
Update-Module -Name Az -Force
175+
} else {
176+
Write-Host "Az module is already up to date. No action needed."
177+
}
178+
}
179+
157180
try{
158181
Import-Module Az.Accounts
159182
}catch{

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

Lines changed: 43 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services: Azure SQL
33
platforms: Azure
44
author: anosov1960,rodrigomonteiro-gbb
55
ms.author: sashan.romontei
6-
ms.date: 04/08/2025
6+
ms.date: 06/21/2025
77
---
88

99
# Overview
@@ -44,66 +44,67 @@ The scripts is seamlessly integrated with Azure Authentication. It uses managed
4444

4545
| **Parameter** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | **Value** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; | **Description** |
4646
|:--|:--|:--|
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.|
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+
|`-ExclusionTags`| `{"name":"value","name":"value"}` |*Optional*. If specified, excludes the resources that have this tag assigned.|
51+
|`-TenantId`| `tenant_id` |*Optional*. If specified, uses this tenant id to log in. Otherwise, the current context is used.|
52+
|`-ReportOnly`| |*Optional*. If true, generates a csv file with the list of resources that are to be modified, but doesn't make the actual change.|
53+
|`-UseManagedIdentity`| |*Optional*. If true, logs in both PowerShell and CLI using managed identity. Required to run the script as a runbook.|
5154

5255
# Logging & Error Handling
5356

5457
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.
5558

56-
# Customizations
59+
# Reporting
60+
61+
The script produces a report listing the affected resources by creating a `ModifiedResources_{yyyyMMdd_HHmmss}.csv` file that contains the following information about each resource:
62+
63+
- Tenant id
64+
- Subscription id
65+
- Resource name
66+
- Resource type
67+
- Status
68+
- Original license type
69+
- Resource group
70+
- Location
71+
72+
> [!NOTE]
73+
> - If `-ReportOnly` is specified, the report shows the resources that would be affected without the actuall change being applied.
5774
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.
5975

6076
# Script execution examples
6177

6278
## Example 1
6379

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.
80+
The following command will scan all the subscriptions in tenant `<tenant_id>`, and generates the list of the resources that would change the license type to "LicenseIncluded".
6581

6682
```PowerShell
67-
.\modify-license-type.ps1 -LicenseType LicenseIncluded
83+
.\modify-azure-sql-license-type.ps1 -TenantId <tenant_id> -LicenseType LicenseIncluded -ReportOnly
6884
```
6985

7086
## Example 2
7187

72-
The following command will scan a specific subscription, and set the license type to pay-as-you-go on all SQL resources.
88+
The following command will scan resource group `<resource_group_name>` in the subscription `<sub_id>` within the current tenant, set the license type value to "LicenseIncluded" on each resource that has a different license type.
7389

7490
```PowerShell
75-
.\modify-license-type.ps1 -SubId <sub_id> -LicenseType LicenseIncluded
91+
.\modify-azure-sql-license-type.ps1 -SubId <sub_id> -ResourceGroup <resource_group_name> -LicenseType LicenseIncluded
7692
```
7793

7894
## Example 3
7995

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.
96+
The following command will scan all subscriptions in the account using managed identity, set the license type value to "LicenseIncluded" on all resources in tenant <tenant_id> that have a different license type. The resources with the tag `Environment:Dev` will be excluded.
8197

8298
```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+
.\modify-azure-sql-license-type.ps1 -TenantId <tenant_id> -LicenseType LicenseIncluded -UseManagedIdentity -ExclusionTags {"Environment":"Dev"}
99100
100101
# Running the script using Cloud Shell
101102
102103
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.
103104
104105
1. Launch the [Cloud Shell](https://shell.azure.com/). For details, [read more about PowerShell in Cloud Shell](https://aka.ms/pscloudshell/docs).
105106
106-
1. Connect to Azure AD. You must specify `<tenant_id>` if you have access to more than one AAD tenants.
107+
1. Connect to Azure AD. You can skip this step if you specify `<tenant_id>` as a parameter of the script.
107108
108109
```console
109110
Connect-AzureAD -TenantID <tenant_id>
@@ -112,65 +113,30 @@ This option is recommended because Cloud shell has the Azure PowerShell modules
112113
1. Upload the script to your cloud shell using the following command:
113114
114115
```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+
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-azure-sql-license-type/modify-azure-sql-license-type.ps1 -o modify-azure-sql-license-type.ps1
116117
```
117118
118-
1. Execute the command as shown by the examples.
119+
1. Run the script.
119120
120121
> [!NOTE]
121122
> - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on MacOS.
122123
> - The script will be uploaded directly to the home folder associated with your Cloud Shell session.
123124
124-
# Schedule the script execution using Azure Runbook
125+
# Running the script from a PC
125126
126-
You can schedule the command to run as a runbook. Follow these steps using the Azure Portal:
127127
128-
### 1. Download the Script
128+
Use the following steps to run the script in a PowerShell session on your PC.
129129
130-
Open a command shell on your device and dowload the script to to your current folder.
130+
1. Copy the script to your current folder:
131131
132-
```console
133-
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/refs/heads/master/samples/manage/azure-hybrid-benefit/modify-license-type/modify-license-type.ps1
134-
```
135-
### 2. Create or Use an Existing Automation Account
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-
138-
### 3. Import the Runbook
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-
150-
### 4. Publish the Runbook
151-
After the runbook is imported, click the **Publish** button to make it available for scheduling.
152-
153-
### 5. Link the Runbook to a Schedule
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-
163-
### 6. Configure Runbook Parameters
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.
132+
```console
133+
curl https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/modify-azure-sql-license-type/modify-azure-sql-license-type.ps1 -o modify-azure-sql-license-type.ps1
134+
```
168135
169-
### 7. Verify the Runbook Execution
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 `
136+
1. Connect to Azure AD. You can skip this step if you specify `<tenant_id>` as a parameter of the script.
173137
174-
Your license is now active.
138+
```console
139+
Connect-AzureAD -TenantID <tenant_id>
140+
```
175141
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)
142+
1. Run the script by following an appropriate example.

0 commit comments

Comments
 (0)