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
|-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,11 +78,24 @@ 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 `<db_name>` on a SQL Server instance `<sql_server_name>.database.windows.net`. It will prompt for the database user name and password.
The following command uses the parameter splatting method to achieve the same outcome as Example 3.
91
+
92
+
```PowerShell
93
+
$params =@{
94
+
Server="my-westus2-server.database.windows.net";
95
+
Database="sql-license-usage";
96
+
Cred=Get-Credential;
97
+
}
98
+
.\sql-license-usage.ps1 @params
87
99
```
88
100
89
101
# Running the script using Cloud Shell
@@ -108,17 +120,31 @@ Use the following steps to calculate the SQL Server license usage:
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
112
-
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.
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.
126
+
127
+
1. [Create a new automation account](https://ms.portal.azure.com/#create/Microsoft.AutomationAccount) or use an existing one.
128
+
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 and save data.
129
+
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.
130
+
- Az.Accounts
131
+
- Az.Compute
132
+
- Az.DataFactory
133
+
- Az.Resources
134
+
- Az.Sql
135
+
- Az.SqlVirtualMachine
136
+
1. Select *Runbooks* in the **Process automation** group and create a new PowerShell runbook. Open it and click on the *Edit* button.
137
+
1. Open the [script file](https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/manage/azure-hybrid-benefit/sql-license-usage.ps1), copy the entire file and paste it into the editor, click on *Save* and then click on *Publish*.
138
+
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.
139
+
1. Click on *Parameters and run settings* and specify the following parameters:
140
+
- SUBID. Leave it blank if you want to scan all the subscriptions
141
+
- SERVER. Put in the SQL Server connection endpoint (e.g. my-westus2-sql-server.database.windows.net)
142
+
- CRED. Put in the name of the credential object you created in Step 2.
143
+
- DATABASE. Put in the database name where you want to save the license information.
144
+
- USEINRUNBOOKS. Select True.
145
+
146
+
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
147
115
148
>[!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.
118
-
> - Your automation account must have the following modules installed. If not, add them from the Gallery.
119
-
> - Az.Accounts
120
-
> - Az.Compute
121
-
> - Az.DataFactory
122
-
> - Az.Resources
123
-
> - Az.Sql
124
-
> - Az.SqlVirtualMachine
149
+
> - 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.
150
+
> - When running the script as a runbook, it is b=necessary to use a database to ensure that the results can be analyzed outside of the runbook.
0 commit comments