mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
services, platforms, author, ms.author, ms.date
| services | platforms | author | ms.author | ms.date |
|---|---|---|---|---|
| Azure SQL | Azure | anosov1960 | sashan | 06/12/2024 |
Overview
This script performes a scheduled activation of a SQL Server p-core license.
Required permissions
Your RBAC role must include the following permissions:
- Microsoft.AzureArcData/SqlLicenses/read
- Microsoft.AzureArcData/SqlLicenses/write
- Microsoft.Management/managementGroups/read
- Microsoft.Resources/subscriptions/read
- Microsoft.Resources/subscriptions/resourceGroups/read
- Microsoft.Support/supporttickets/write
Launching the script
The script accepts the following command line parameters:
| Parameter | Value | Description |
|---|---|---|
| -LicenseId | License resource URI | |
| -UseInRunbook | $True or $False (default) | Optional: must be $True when executed as a Runbook |
Example
The following command activate the license
.\activate-pcore-license.ps1 -LicenseID <rsource URI>
Running the script using Cloud Shell
To run the script in the Cloud Shell, use the following steps:
-
Launch the Cloud Shell. For details, read PowerShell in Cloud Shell.
-
Upload the script to the shell using the following command:
curl https://raw.githubusercontent.com/anosov1960/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/activate-pcore-license/activate-pcore-license.md -o activate-pcore-license.ps1 -
Run the script with a set of parameters that reflect your desired configuration.
.\activate-pcore-license.ps1 -licenseID <resource URI>
Note
- To paste the commands into the shell, use
Ctrl-Shift-Von Windows orCmd-von MacOS.- The
curlcommand will copy the script directly to the home folder associated with your Cloud Shell session.
Running the script as a Azure runbook
You can scahedule to run the the command as a runbook. To set it up using Azure Portal, follow these steps.
- Open a command shell on your device and run this command. It will copy the script to your local folder.
curl https://raw.githubusercontent.com/anosov1960/sql-server-samples/master/samples/manage/azure-arc-enabled-sql-server/activate-pcore-license/activate-pcore-license.md -o activate-pcore-license.ps1
- Create a new automation account or open an existing one.
- Select Run as accounts in the Account Settings group, open the automatically created Azure Run As Account and note or copy the Display Name property. You must add this user to all the target subscriptions with at least a Reader access role. To collect the Unregistered vCores, the user must be at least a Contributor. See Role assignment portal for the instructions about role assignments.
- Select Credentials in the Shared resources group and create a credential object with the database username and password. The script will use these to connect to the specified database to save the license utilization data.
- Select Modules in the Shared resources group and make sure your automation account have the following PowerShell modules installed. If not, add them from the Gallery.
- Az.Accounts
- Az.Resources
- Select Runbooks in the Process automation group and click on Import a runbook, select the file you downloaded in Step 1 and click Create.
- When import is completed, click the Publish button.
- From the runbook blade, click on the Link to schedule button and select an existing schedule or create a new one with the desired frequency of runs and the expiration time.
- Click on Parameters and run settings and specify the following parameters:
- LICENSEID. Put in teh resourec URI
- USEINRUNBOOKS. Select True to activate the logic that authenticates the runbook using the Azure Run As Account.
- Click OK to link to the schedule and OK again to create the job.
For more information about the runbooks, see the Runbook tutorial