Skip to content

Commit dc25e53

Browse files
authored
Merge pull request #915 from anosov1960/master
Made reporting of self-hosted SQL servers optional.
2 parents 34ccbca + a76d855 commit dc25e53

2 files changed

Lines changed: 62 additions & 53 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ The following resources are in scope for the license utilization analysis:
4949

5050
The script accepts the following command line parameters:
5151

52-
| **Parameter**                                 | **Value**                                                                       | **Description** |
52+
| **Parameter**                                         | **Value**                                                                       | **Description** |
5353
|:--|:--|:--|
5454
|-SubId|subscription_id *or* a file_name|Optional: subscription id or a .csv file with the list of subscriptions<sup>1</sup>|
5555
|-UseInRunbook| \$True or \$False (default) |Optional: must be $True when executed as a Runbook|
5656
|-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 |
5757
|-Database|database_name|Optional: database name where data will be saved.<br> Must be accompanied by -Server and -Cred|
5858
|-Cred|credential_object|Optional: value of type PSCredential to securely pass database user and password|
5959
|-FilePath|csv_file_name|Optional: filename where the data will be saved in a .csv format. Ignored if database parameters are specified|
60+
|-ShowUnregistered|\$True or \$False (default)|Optional: causes the script to report the total size of VMs that self-host SQL server instance that is unregistered with the IaaS SQL extension|
6061

6162
<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.
6263
```PowerShell

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

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
# -Cred [credential_object] (Required to save data to the database)
2424
# -FilePath [csv_file_name] (Required to save data in a .csv format. Ignored if database parameters are specified)
2525
# -UseInRunbook [True] | [False] (Required when executed as a Runbook)
26+
# -ShowUnregistered [True] | [False] (Optional. If specified, checks every VM if SQL server is installed)
2627
#
2728

2829
param (
2930
[Parameter (Mandatory= $false)]
30-
[string] $SubId,
31+
[string] $SubId = '4f6d3845-d3e3-4c31-bdf0-c73464aaff0e',
3132
[Parameter (Mandatory= $false)]
3233
[string] $Server,
3334
[Parameter (Mandatory= $false)]
@@ -39,7 +40,10 @@ param (
3940
[Parameter (Mandatory= $false)]
4041
[bool] $UseInRunbook = $false,
4142
[Parameter (Mandatory= $false)]
42-
[bool] $ShowEC = $false
43+
[bool] $ShowEC = $false,
44+
[Parameter (Mandatory= $false)]
45+
[bool] $ShowUnregistered = $false
46+
4347
)
4448

4549
function CheckModule ($m) {
@@ -418,32 +422,34 @@ foreach ($sub in $subscriptions){
418422
}
419423
}
420424
else {
421-
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
422-
$params =@{
423-
ResourceGroupName = $_.ResourceGroupName
424-
Name = $_.Name
425-
CommandId = 'RunPowerShellScript'
426-
ScriptPath = 'DiscoverSql.ps1'
427-
ErrorAction = 'Stop'
428-
}
429-
}
430-
else {
431-
$params =@{
432-
ResourceGroupName = $_.ResourceGroupName
433-
Name = $_.Name
434-
CommandId = 'RunShellScript'
435-
ScriptPath = 'DiscoverSql.sh'
436-
ErrorAction = 'Stop'
437-
}
438-
}
439-
try {
440-
$out = Invoke-AzVMRunCommand @params
441-
if ($out.Value[0].Message.Contains('True')){
442-
$($using:subtotal).unreg_sqlvm += $vCores
443-
}
444-
}
445-
catch {
446-
write-host $params.Name "No acceaa"
425+
if ($($using:ShowUnregistered)){
426+
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
427+
$params =@{
428+
ResourceGroupName = $_.ResourceGroupName
429+
Name = $_.Name
430+
CommandId = 'RunPowerShellScript'
431+
ScriptPath = 'DiscoverSql.ps1'
432+
ErrorAction = 'Stop'
433+
}
434+
}
435+
else {
436+
$params =@{
437+
ResourceGroupName = $_.ResourceGroupName
438+
Name = $_.Name
439+
CommandId = 'RunShellScript'
440+
ScriptPath = 'DiscoverSql.sh'
441+
ErrorAction = 'Stop'
442+
}
443+
}
444+
try {
445+
$out = Invoke-AzVMRunCommand @params
446+
if ($out.Value[0].Message.Contains('True')){
447+
$($using:subtotal).unreg_sqlvm += $vCores
448+
}
449+
}
450+
catch {
451+
write-host $params.Name "No acceaa"
452+
}
447453
}
448454
}
449455
}
@@ -456,31 +462,33 @@ foreach ($sub in $subscriptions){
456462
AddVCores -Tier $sql_vm.Sku -LicenseType $sql_vm.LicenseType -CoreCount $vCores
457463
}
458464
else {
459-
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
460-
$params =@{
461-
ResourceGroupName = $_.ResourceGroupName
462-
Name = $_.Name
463-
CommandId = 'RunPowerShellScript'
464-
ScriptPath = 'DiscoverSql.ps1'
465-
ErrorAction = 'Stop'
466-
}
467-
}
468-
else {
469-
$params =@{
470-
ResourceGroupName = $_.ResourceGroupName
471-
Name = $_.Name
472-
CommandId = 'RunShellScript'
473-
ScriptPath = 'DiscoverSql.sh'
474-
ErrorAction = 'Stop'
475-
}
476-
}try {
477-
$out = Invoke-AzVMRunCommand @params
478-
if ($out.Value[0].Message.Contains('True')){
479-
$subtotal.unreg_sqlvm += $vCores
465+
if ($ShowUnregistered){
466+
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
467+
$params =@{
468+
ResourceGroupName = $_.ResourceGroupName
469+
Name = $_.Name
470+
CommandId = 'RunPowerShellScript'
471+
ScriptPath = 'DiscoverSql.ps1'
472+
ErrorAction = 'Stop'
473+
}
474+
}
475+
else {
476+
$params =@{
477+
ResourceGroupName = $_.ResourceGroupName
478+
Name = $_.Name
479+
CommandId = 'RunShellScript'
480+
ScriptPath = 'DiscoverSql.sh'
481+
ErrorAction = 'Stop'
482+
}
483+
}try {
484+
$out = Invoke-AzVMRunCommand @params
485+
if ($out.Value[0].Message.Contains('True')){
486+
$subtotal.unreg_sqlvm += $vCores
487+
}
488+
}
489+
catch {
490+
write-host $params.Name "No acceaa"
480491
}
481-
}
482-
catch {
483-
write-host $params.Name "No acceaa"
484492
}
485493
}
486494
}

0 commit comments

Comments
 (0)