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
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.
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`.
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.
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`
The following command will disable ESU on all servers in the subscriptions `<sub_id>`.
103
105
104
106
```console
105
-
.\modify-license-type.ps1 -SubId <sub_id> -EnableESU No
107
+
.\modify-arc-sql-license-type.ps1 -SubId <sub_id> -EnableESU No
106
108
```
107
109
108
110
## Example 6
109
111
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.
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
|-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.|
51
54
52
55
# Logging & Error Handling
53
56
54
57
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.
55
58
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.
57
74
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.
59
75
60
76
# Script execution examples
61
77
62
78
## Example 1
63
79
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".
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.
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.
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
104
105
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
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.
107
108
108
109
```console
109
110
Connect-AzureAD -TenantID <tenant_id>
@@ -112,65 +113,30 @@ This option is recommended because Cloud shell has the Azure PowerShell modules
112
113
1. Upload the script to your cloud shell using the following command:
### 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.
- 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.
173
137
174
-
Your license is now active.
138
+
```console
139
+
Connect-AzureAD -TenantID <tenant_id>
140
+
```
175
141
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