Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/manage/azure-hybrid-benefit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ms.date: 12/15/2020

# Overview

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 down into the following categories of licenses:
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:

- AHB Standard vCores
- AHB Enterprise vCores
Expand Down Expand Up @@ -58,6 +58,6 @@ If you need to scan a subset of the subscriptions, use the following steps:

> [!NOTE]
> - To paste the commands into the shell, use `Ctrl-Shift-V` on Windows or `Cmd-v` on MacOS.
> - The script will be uploaded directly to the home folder associated with your Cloud Shell session.
> - The `curl` command will copy the script directly to the home folder associated with your Cloud Shell session.
> - The script will prompt for the resource group name and print a message when migration is completed.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Set-AzContext -SubscriptionId $SubcriptionId
$total_std_vcores = 0
$total_ent_vcores = 0

#Get all SQL databadses in the subscription
#Get all SQL databases in the subscription
$databases = Get-AzSqlServer | Get-AzSqlDatabase

# Get the databases with License Included and add to VCore count
Expand Down
99 changes: 58 additions & 41 deletions samples/manage/azure-hybrid-benefit/sql-license-usage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ if ($args[0] -ne $null) {
}

[System.Collections.ArrayList]$usage = @()
$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"))
if ($ec -eq $null){
$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"))
}else{
$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"))
}
$total = [pscustomobject]@{ahb_std=0; ahb_ent=0; payg_std=0; payg_ent=0; hadr_std=0; hadr_ent=0; developer=0; express=0}


#Save the VM SKU table
$VM_SKUs = Get-AzComputeResourceSku
Expand All @@ -61,70 +67,70 @@ foreach ($sub in $subscriptions){
}

# Total counts of different license types
$total = [pscustomobject]@{ahb_std=0; ahb_ent=0; payg_std=0; payg_ent=0; hadr_std=0; hadr_ent=0; developer=0; express=0}
$subtotal = [pscustomobject]@{ahb_std=0; ahb_ent=0; payg_std=0; payg_ent=0; hadr_std=0; hadr_ent=0; developer=0; express=0}

#Get all logical servers
$servers = Get-AzSqlServer

#Get all SQL databadse resources in the subscription
#Get all SQL database resources in the subscription
$databases = $servers | Get-AzSqlDatabase

# Get the databases with License Included and add to VCore count
# Process the vCore-based databases
foreach ($db in $databases ){
if ($db.SkuName -eq "ElasticPool") {continue}

if ($db.LicenseType -eq "LicenseIncluded") {
if ($db.Edition -eq "BusinessCritical") {
$total.ahb_ent += $db.Capacity
$subtotal.ahb_ent += $db.Capacity
} elseif ($db.Edition -eq "GeneralPurpose") {
$total.ahb_std += $db.Capacity
$subtotal.ahb_std += $db.Capacity
}
}else{
if ($db.Edition -eq "BusinessCritical") {
$total.payg_ent += $db.Capacity
$subtotal.payg_ent += $db.Capacity
} elseif ($db.Edition -eq "GeneralPurpose") {
$total.payg_std += $db.Capacity
}$table
$subtotal.payg_std += $db.Capacity
}
}
}

#Get all SQL elastic pool resources in the subscription
$pools = $servers | Get-AzSqlElasticPool

# Get the elastic pools with License Included and and add to VCore count
# Process the vCore-based elastic pools
foreach ($pool in $pools){
if ($pool.LicenseType -eq "LicenseIncluded") {
if ($pool.Edition -eq "BusinessCritical") {
$total.ahb_ent += $pool.Capacity
$subtotal.ahb_ent += $pool.Capacity
} elseif ($pool.Edition -eq "GeneralPurpose") {
$total.ahb_std += $pool.Capacity
$subtotal.ahb_std += $pool.Capacity
}
}else{
if ($pool.Edition -eq "BusinessCritical") {
$total.payg_ent += $pool.Capacity
$subtotal.payg_ent += $pool.Capacity
} elseif ($pool.Edition -eq "GeneralPurpose") {
$total.payg_std += $pool.Capacity
$subtotal.payg_std += $pool.Capacity
}
}
}

#Get all SQL managed instance resources in the subscription
$instances = Get-AzSqlInstance

# Get the SQL managed instances with License Included and add to VCore count
# Process the SQL managed instances with License Included and add to VCore count
foreach ($ins in $instances){
if ($ins.InstancePoolName -eq $null){
if ($ins.LicenseType -eq "LicenseIncluded") {
if ($ins.Sku.Tier -eq "BusinessCritical") {
$total.ahb_ent += $ins.VCores
$subtotal.ahb_ent += $ins.VCores
} elseif ($ins.Sku.Tier -eq "GeneralPurpose") {
$total.ahb_std += $ins.VCores
$subtotal.ahb_std += $ins.VCores
}
}else{
if ($ins.Edition -eq "BusinessCritical") {
$total.payg_ent += $pool.Capacity
$subtotal.payg_ent += $pool.Capacity
} elseif ($ins.Edition -eq "GeneralPurpose") {
$total.payg_std += $ins.Capacity
$subtotal.payg_std += $ins.Capacity
}
}
}
Expand All @@ -133,19 +139,19 @@ foreach ($sub in $subscriptions){
#Get all instance pool resources in the subscription
$ipools = Get-AzSqlInstancePool

# Get the instance pools with License Included and add to VCore count
# Process the instance pools
foreach ($ip in $ipools){
if ($ip.LicenseType -eq "LicenseIncluded") {
if ($ip.Edition -eq "BusinessCritical") {
$total.ahb_ent += $ip.VCores
$subtotal.ahb_ent += $ip.VCores
} elseif ($ip.Edition -eq "GeneralPurpose") {
$total.ahb_std += $ip.VCores
$subtotal.ahb_std += $ip.VCores
}
}else{
if ($ip.Edition -eq "BusinessCritical") {
$total.payg_ent += $ip.Capacity
$subtotal.payg_ent += $ip.Capacity
} elseif ($ip.Edition -eq "GeneralPurpose") {
$total.payg_std += $ip.Capacity
$subtotal.payg_std += $ip.Capacity
}
}
}
Expand All @@ -165,19 +171,19 @@ foreach ($sub in $subscriptions){
if ($ssis_ir.State -eq "Started"){
if ($ssis_ir.LicenseType -like "LicenseIncluded"){
if ($ssis_ir.Edition -like "Enterprise"){
$total.ahb_ent += $vcpu.value
$subtotal.ahb_ent += $vcpu.value
}elseif ($ssis_ir.Edition -like "Standard"){
$total.ahb_std += $vcpu.value
$subtotal.ahb_std += $vcpu.value
}
}elseif ($data.license -like "BasePrice"){
if ($ssis_ir.Edition -like "Enterprise"){
$total.payg_ent += $vcpu.value
$subtotal.payg_ent += $vcpu.value
}elseif ($ssis_ir.Edition -like "Standard"){
$total.payg_std += $vcpu.value
$subtotal.payg_std += $vcpu.value
}elseif ($ssis_ir.Edition -like "Developer"){
$total.developer += $vcpu.value
$subtotal.developer += $vcpu.value
}elseif ($ssis_ir.Edition -like "Express"){
$total.express += $vcpu.value
$subtotal.express += $vcpu.value
}
}
}
Expand All @@ -201,33 +207,44 @@ foreach ($sub in $subscriptions){

if ($data.license -like "DR"){
if ($data.sku -like "Enterprise"){
$total.hadr_ent += $data.vcpus
$subtotal.hadr_ent += $data.vcpus
}elseif ($data.sku -like "Standard"){
$total.hadr_std += $data.vcpus
$subtotal.hadr_std += $data.vcpus
}
}elseif ($data.license -like "AHUB"){
if ($data.sku -like "Enterprise"){
$total.ahb_ent += $data.vcpus
$subtotal.ahb_ent += $data.vcpus
}elseif ($data.sku -like "Standard"){
$total.ahb_std += $data.vcpus
$subtotal.ahb_std += $data.vcpus
}
}elseif ($data.license -like "PAYG"){
if ($data.sku -like "Enterprise"){
$total.payg_ent += $data.vcpus
$subtotal.payg_ent += $data.vcpus
}elseif ($data.sku -like "Standard"){
$total.payg_std += $data.vcpus
$subtotal.payg_std += $data.vcpus
}elseif ($data.sku -like "Developer"){
$total.developer += $data.vcpus
$subtotal.developer += $data.vcpus
}elseif ($data.sku -like "Express"){
$total.express += $data.vcpus
$subtotal.express += $data.vcpus
}
}
}
}


$usage += ,(@($sub.Name, $sub.Id, $total.ahb_std, $total.ahb_ent, $total.payg_std, $total.payg_ent, $total.hadr_std, $total.hadr_ent, $total.developer, $total.express))

foreach( $property in $total.psobject.properties.name ){
$total.$property += $subtotal.$property
}
if ($ec -eq $null){
$usage += ,(@($sub.Name, $sub.Id, $subtotal.ahb_std, $subtotal.ahb_ent, $subtotal.payg_std, $subtotal.payg_ent, $subtotal.hadr_std, $subtotal.hadr_ent, $subtotal.developer, $subtotal.express))
}else{
$usage += ,(@($sub.Name, $sub.Id, ($subtotal.ahb_std + $subtotal.ahb_ent*4), ($subtotal.payg_std + $subtotal.payg_ent*4), $subtotal.ahb_std, $subtotal.ahb_ent, $subtotal.payg_std, $subtotal.payg_ent, $subtotal.hadr_std, $subtotal.hadr_ent, $subtotal.developer, $subtotal.express))
}
}

if ($ec -eq $null){
$usage += ,(@("Total", $null, $total.ahb_std, $total.ahb_ent, $total.payg_std, $total.payg_ent, $total.hadr_std, $total.hadr_ent, $total.developer, $total.express))
}else{
$usage += ,(@("Total", $null, ($total.ahb_std + $total.ahb_ent*4), ($total.payg_std + $total.payg_ent*4), $total.ahb_std, $total.ahb_ent, $total.payg_std, $total.payg_ent, $total.hadr_std, $total.hadr_ent, $total.developer, $total.express))
}

$table = ConvertFrom-Csv ($usage | %{ $_ -join ','} )
Expand Down