mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Merge pull request #915 from anosov1960/master
Made reporting of self-hosted SQL servers optional.
This commit is contained in:
@@ -49,7 +49,7 @@ The following resources are in scope for the license utilization analysis:
|
||||
|
||||
The script accepts the following command line parameters:
|
||||
|
||||
| **Parameter** | **Value** | **Description** |
|
||||
| **Parameter** | **Value** | **Description** |
|
||||
|:--|:--|:--|
|
||||
|-SubId|subscription_id *or* a file_name|Optional: subscription id or a .csv file with the list of subscriptions<sup>1</sup>|
|
||||
|-UseInRunbook| \$True or \$False (default) |Optional: must be $True when executed as a Runbook|
|
||||
@@ -57,6 +57,7 @@ The script accepts the following command line parameters:
|
||||
|-Database|database_name|Optional: database name where data will be saved.<br> Must be accompanied by -Server and -Cred|
|
||||
|-Cred|credential_object|Optional: value of type PSCredential to securely pass database user and password|
|
||||
|-FilePath|csv_file_name|Optional: filename where the data will be saved in a .csv format. Ignored if database parameters are specified|
|
||||
|-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|
|
||||
|
||||
<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.
|
||||
```PowerShell
|
||||
|
||||
@@ -23,11 +23,12 @@
|
||||
# -Cred [credential_object] (Required to save data to the database)
|
||||
# -FilePath [csv_file_name] (Required to save data in a .csv format. Ignored if database parameters are specified)
|
||||
# -UseInRunbook [True] | [False] (Required when executed as a Runbook)
|
||||
# -ShowUnregistered [True] | [False] (Optional. If specified, checks every VM if SQL server is installed)
|
||||
#
|
||||
|
||||
param (
|
||||
[Parameter (Mandatory= $false)]
|
||||
[string] $SubId,
|
||||
[string] $SubId = '4f6d3845-d3e3-4c31-bdf0-c73464aaff0e',
|
||||
[Parameter (Mandatory= $false)]
|
||||
[string] $Server,
|
||||
[Parameter (Mandatory= $false)]
|
||||
@@ -39,7 +40,10 @@ param (
|
||||
[Parameter (Mandatory= $false)]
|
||||
[bool] $UseInRunbook = $false,
|
||||
[Parameter (Mandatory= $false)]
|
||||
[bool] $ShowEC = $false
|
||||
[bool] $ShowEC = $false,
|
||||
[Parameter (Mandatory= $false)]
|
||||
[bool] $ShowUnregistered = $false
|
||||
|
||||
)
|
||||
|
||||
function CheckModule ($m) {
|
||||
@@ -418,32 +422,34 @@ foreach ($sub in $subscriptions){
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunPowerShellScript'
|
||||
ScriptPath = 'DiscoverSql.ps1'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}
|
||||
else {
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunShellScript'
|
||||
ScriptPath = 'DiscoverSql.sh'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}
|
||||
try {
|
||||
$out = Invoke-AzVMRunCommand @params
|
||||
if ($out.Value[0].Message.Contains('True')){
|
||||
$($using:subtotal).unreg_sqlvm += $vCores
|
||||
}
|
||||
}
|
||||
catch {
|
||||
write-host $params.Name "No acceaa"
|
||||
if ($($using:ShowUnregistered)){
|
||||
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunPowerShellScript'
|
||||
ScriptPath = 'DiscoverSql.ps1'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}
|
||||
else {
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunShellScript'
|
||||
ScriptPath = 'DiscoverSql.sh'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}
|
||||
try {
|
||||
$out = Invoke-AzVMRunCommand @params
|
||||
if ($out.Value[0].Message.Contains('True')){
|
||||
$($using:subtotal).unreg_sqlvm += $vCores
|
||||
}
|
||||
}
|
||||
catch {
|
||||
write-host $params.Name "No acceaa"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -456,31 +462,33 @@ foreach ($sub in $subscriptions){
|
||||
AddVCores -Tier $sql_vm.Sku -LicenseType $sql_vm.LicenseType -CoreCount $vCores
|
||||
}
|
||||
else {
|
||||
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunPowerShellScript'
|
||||
ScriptPath = 'DiscoverSql.ps1'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}
|
||||
else {
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunShellScript'
|
||||
ScriptPath = 'DiscoverSql.sh'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}try {
|
||||
$out = Invoke-AzVMRunCommand @params
|
||||
if ($out.Value[0].Message.Contains('True')){
|
||||
$subtotal.unreg_sqlvm += $vCores
|
||||
if ($ShowUnregistered){
|
||||
if ($_.StorageProfile.OSDisk.OSType -eq "Windows"){
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunPowerShellScript'
|
||||
ScriptPath = 'DiscoverSql.ps1'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}
|
||||
else {
|
||||
$params =@{
|
||||
ResourceGroupName = $_.ResourceGroupName
|
||||
Name = $_.Name
|
||||
CommandId = 'RunShellScript'
|
||||
ScriptPath = 'DiscoverSql.sh'
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
}try {
|
||||
$out = Invoke-AzVMRunCommand @params
|
||||
if ($out.Value[0].Message.Contains('True')){
|
||||
$subtotal.unreg_sqlvm += $vCores
|
||||
}
|
||||
}
|
||||
catch {
|
||||
write-host $params.Name "No acceaa"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
write-host $params.Name "No acceaa"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user