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
Copy file name to clipboardExpand all lines: samples/manage/azure-hybrid-benefit/README.md
+58-20Lines changed: 58 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,12 @@ services: Azure SQL
3
3
platforms: Azure
4
4
author: anosov1960
5
5
ms.author: sashan
6
-
ms.date: 1/11/2021
6
+
ms.date: 2/2/2021
7
7
---
8
8
9
9
# Overview
10
10
11
-
This script provides a simple solution to analyze and track the consolidated utilization of SQL Server licenses by all of the SQL resources in a specific subscription or the entire the account. By default, the script scans all subscriptions the user account has access. Alternatively, you can specify a single subscription or a .CSV file with a list of subscription. The usage report includes the following information for each scanned subscription.
11
+
This script provides a simple solution to analyze and track the consolidated utilization of SQL Server licenses by all of the SQL resources in a specific subscription or the entire account. By default, the script scans all subscriptions the user account has access to. Alternatively, you can specify a single subscription or a .CSV file with a list of subscription. The usage report includes the following information for each scanned subscription.
12
12
13
13
|**Category**|**Description**|
14
14
|:--|:--|
@@ -45,15 +45,14 @@ The following resources are in scope for the license utilization analysis:
45
45
46
46
The script accepts the following command line parameters:
|-SubId|subscription_id *or* a file_name|Accepts a .csv file with the list of subscriptions<sup>1</sup>|
51
-
|-UseInRunbook||Must be specified when executed as a Runbook|
52
-
|-Server|[protocol:]server[instance_name][,port]|Required to save data to the database|
53
-
|-Database|database_name|Required to save data to the database|
54
-
|-Username|user_name|Required to save data to the database|
55
-
|-Password|password|Required to save data to the database, must be passed as a *[SecureString]* variable|
56
-
|-FilePath|csv_file_name|Required to save data in a .csv format. Ignored if database parameters are specified|
50
+
|-SubId|subscription_id *or* a file_name|Optional: subscription id or a .csv file with the list of subscriptions<sup>1</sup>|
51
+
|-UseInRunbook|\$True or \$False (default) |Optional: must be $True when executed as a Runbook|
52
+
|-Server|[protocol:]server[instance_name][,port]|Optional: SQL Server connection endpoint to save data to the database.<br> Must be accompanied by -Database and -Cred |
53
+
|-Database|database_name|Optional: database name where data will be saved.<br> Must be accompanied by -Server and -Cred|
54
+
|-Cred|credential_object|Optional: value of type PSCredential to securely pass database user and password|
55
+
|-FilePath|csv_file_name|Optional: filename where the data will be saved in a .csv format. Ignored if database parameters are specified|
57
56
58
57
<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.
59
58
```PowerShell
@@ -79,39 +78,78 @@ The following command will scan the subscription `<sub_id>` and save the results
79
78
80
79
## Example 3
81
80
82
-
The following command will scan all the subscriptions in the account and save the results in a SQL database `<db_name>` on a SQL Server instance `<sql_server_name>.database.windows.net`.
81
+
The following command will scan all the subscriptions in the account and save the results in a SQL database `sql-license-usage` on a SQL Server instance `my-westus2-server.database.windows.net`. It will prompt for the database user name and password.
3. Run the script with a set of parameters that reflect your desired configuration.
102
114
103
115
```console
104
-
./sql-license-usage.ps1 <parameters>
116
+
./sql-license-usage.ps1 <parameters>
105
117
```
106
118
107
119
> [!NOTE]
108
120
> - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on MacOS.
109
121
> - The `curl`command will copy the script directly to the home folder associated with your Cloud Shell session.
110
122
111
-
# Tracking SQL license usage over time
123
+
# Running the script as a Azure runbook
124
+
125
+
You can track your license utilization over time by running this script on schedule as a runbook. To set it up using Azure Portal, follow these steps.
112
126
113
-
You can track your license utilization over time by periodically running this script. To schedule automatic execution of the script, create a PowerShell runbook using an Azure Automation account. See the [Runbook tutorial](https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-powershell) for the details of how to create a PowerShell runbook. Because the script accesses the resources across multiple subscriptions, the runbook must be able to authenticate using the Run As account that was automatically created when you created your Automation account. The logic required for the Runbooks is part of the script.
127
+
1. Open a command shell on your device and run this command. It will copy the script to your local folder.
2.[Create a new automation account](https://ms.portal.azure.com/#create/Microsoft.AutomationAccount) or open an existing one.
132
+
1. Select *Rus 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 subscriptions you wish to scan with the *Reader* access role. See [Role assignment portal](https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal) for the instructions about role assignments.
133
+
1. 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.
134
+
1. 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.
135
+
- Az.Accounts
136
+
- Az.Compute
137
+
- Az.DataFactory
138
+
- Az.Resources
139
+
- Az.Sql
140
+
- Az.SqlVirtualMachine
141
+
1. Select *Runbooks* in the **Process automation** group and click on *Import a runbook*, select the file you downloaded in Step 1 and click **Create**.
142
+
1. When import is completed, click the *Publish* button.
143
+
1. 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.
144
+
1. Click on *Parameters and run settings* and specify the following parameters:
145
+
- SUBID. Put in a subscription ID or leave it blank if you want to scan all the subscriptions the *Azure Run As Account* has been given access to in Step 3.
146
+
- SERVER. Put in the SQL Server connection endpoint (e.g. my-westus2-sql-server.database.windows.net)
147
+
- CRED. Put in the name of the credential object you created in Step 4.
148
+
- DATABASE. Put in the database name where you want to save the license utilization data.
149
+
- USEINRUNBOOKS. Select True to activate the logic that authenticates the runbook using the *Azure Run As Account*.
150
+
1. Click **OK** to link to the schedule and **OK** again to create the job.
151
+
152
+
For more information about the runbooks, see the [Runbook tutorial](https://docs.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual-powershell)
114
153
115
154
>[!IMPORTANT]
116
-
> - When running the script as a runbook, use a database to ensure that the results can be analyzed outside of the runbook.
117
-
> - You must specify a *-UseInRunbook* switch to ensure that the runbook is authenticated using the Run As account.
155
+
> When running the script as a runbook, it is necessary to save the data in a database so that the results could be analyzed outside of the runbook.
0 commit comments