Skip to content

Commit d788bb0

Browse files
Alexander NosovAlexander Nosov
authored andcommitted
added timestamp to the file name
1 parent 5fd497d commit d788bb0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

samples/manage/azure-hybrid-benefit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.date: 12/15/2020
88

99
# Overview
1010

11-
This script is provided to help you manage the SQL Server licenses that are consumed by the SQL Servers deployed to Azure. The script's output is a `sql-license-usage.csv` file with the consolidated SQL Server license usage by all SQL resources in the specific subscriptions or the entire account. The usage is broken into the following license categories:
11+
This script is provided to help you manage the SQL Server licenses that are consumed by the SQL Servers deployed to Azure. The script's output is a `sql-license-usage_<timestamp>.csv` file with the consolidated SQL Server license usage by all SQL resources in the specific subscriptions or the entire account. By periodically generating the usage report you can track your license utilization over time. The usage is broken into the following license categories:
1212

1313
- AHB Standard vCores
1414
- AHB Enterprise vCores

samples/manage/azure-hybrid-benefit/sql-license-usage.ps1

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@ if ($args[0] -ne $null) {
4040
}
4141
}
4242

43+
#Initialize arrays
4344
[System.Collections.ArrayList]$usage = @()
4445
if ($ec -eq $null){
4546
$usage += ,(@("Subscription Name", "Subscription ID", "AHB Std vCores", "AHB Ent vCores", "PAYG Std vCores", "PAYG Ent vCores", "HADR Std vCores", "HADR Ent vCores", "Developer vCores", "Express vCores"))
4647
}else{
4748
$usage += ,(@("Subscription Name", "Subscription ID", "AHB ECs", "PAYG ECs", "AHB Std vCores", "AHB Ent vCores", "PAYG Std vCores", "PAYG Ent vCores", "HADR Std vCores", "HADR Ent vCores", "Developer vCores", "Express vCores"))
4849
}
49-
$total = [pscustomobject]@{ahb_std=0; ahb_ent=0; payg_std=0; payg_ent=0; hadr_std=0; hadr_ent=0; developer=0; express=0}
5050

51+
$subtotal = [pscustomobject]@{ahb_std=0; ahb_ent=0; payg_std=0; payg_ent=0; hadr_std=0; hadr_ent=0; developer=0; express=0}
52+
$total = [pscustomobject]@{}
53+
foreach( $property in $subtotal.psobject.properties.name ){
54+
$total | Add-Member -MemberType NoteProperty -Name $property -Value 6
55+
}
5156

5257
#Save the VM SKU table
5358
$VM_SKUs = Get-AzComputeResourceSku
@@ -66,9 +71,11 @@ foreach ($sub in $subscriptions){
6671
{continue}
6772
}
6873

69-
# Total counts of different license types
70-
$subtotal = [pscustomobject]@{ahb_std=0; ahb_ent=0; payg_std=0; payg_ent=0; hadr_std=0; hadr_ent=0; developer=0; express=0}
71-
74+
# Reset the subtotals
75+
foreach( $property in $subtotal.psobject.properties.name ){
76+
$subtotal.$property = 0
77+
}
78+
7279
#Get all logical servers
7380
$servers = Get-AzSqlServer
7481

@@ -231,7 +238,8 @@ foreach ($sub in $subscriptions){
231238
}
232239
}
233240

234-
foreach( $property in $total.psobject.properties.name ){
241+
# Increment the totals and add subtotals to the usage array
242+
foreach( $property in $subtotal.psobject.properties.name ){
235243
$total.$property += $subtotal.$property
236244
}
237245
if ($ec -eq $null){
@@ -249,6 +257,7 @@ if ($ec -eq $null){
249257

250258
$table = ConvertFrom-Csv ($usage | %{ $_ -join ','} )
251259
$table | Format-table
260+
$fileName = '.\sql-license-usage_' + (Get-Date -f yyyy-MM-dd_HH-mm-ss) + '.csv'
252261
$table | Export-Csv .\sql-license-usage.csv -NoTypeInformation
253262

254263
Write-Host ([Environment]::NewLine + "-- The usage data is saved to .\sql-license-usage.csv")

0 commit comments

Comments
 (0)