Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 197bb0c

Browse files
authored
Edit script for accomodating SqlManagementMode changes (#394)
* adding script to get SQLIaaSExtension health status * convert to .psm1 * Remove SqlManagementMode dependency * identify lightweight VMs
1 parent 994a8d6 commit 197bb0c

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

sql-virtual-machine/get-sqliaasextension-healthstatus/GetSqlVirtualMachinesExtensionHealthStatus.psm1

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,28 @@ function Get-SqlVmList() {
131131
$vmList = [System.Collections.ArrayList]@()
132132

133133
$vmsInSub = Get-AzSqlVM
134-
# We will get all VMs that are Windows and having SqlManagementType as Full
134+
# We will get all VMs that are Windows
135+
if ($PSVersionTable.PSVersion.Major -eq 7)
136+
{
137+
135138
foreach ($vm in $vmsInSub) {
136-
if (($vm.Sku -ne 'Unknown') -and ($vm.Offer -like '*WS*') -and ($vm.SqlManagementType -eq 'Full')) {
139+
$vmObject = $vm | ConvertFrom-Json
140+
$sqlImageOffer = $vmObject.properties.sqlImageOffer
141+
$sqlImageSku = $vmObject.properties.sqlImageSku
142+
if (($sqlImageSku -ne 'Unknown') -and ($sqlImageOffer -like '*WS*')) {
143+
$tmp = $vmList.Add($vm)
144+
}
145+
}
146+
}
147+
elseif ($PSVersionTable.PSVersion.Major -eq 5)
148+
{
149+
foreach ($vm in $vmsInSub) {
150+
if (($vm.Sku -ne 'Unknown') -and ($vm.Offer -like '*WS*')) {
137151
$tmp = $vmList.Add($vm)
152+
}
138153
}
139154
}
155+
140156
return , $vmList
141157
}
142158

@@ -186,6 +202,9 @@ function Get-SqlVmExtensionStatusFromList(
186202
}
187203
'Not supported Extension version' {
188204
$tmp = $Global:NotSupportedVMs.Add($vm)
205+
}
206+
'Lightweight VM' {
207+
$tmp = $Global:LightweightVMs.Add($vm)
189208
}
190209
Default {
191210
$tmp = $Global:FailedVMs.Add($vm)
@@ -286,6 +305,7 @@ $Global:SubscriptionsFailedToConnect = [System.Collections.ArrayList]@()
286305
$Global:HealthyVMs = [System.Collections.ArrayList]@()
287306
$Global:UnHealthyVMs = [System.Collections.ArrayList]@()
288307
$Global:NotSupportedVMs = [System.Collections.ArrayList]@()
308+
$Global:LightweightVMs = [System.Collections.ArrayList]@()
289309
$Global:FailedVMs = [System.Collections.ArrayList]@()
290310
$Global:LogFile = $null
291311
$Global:ReportFile = $null
@@ -301,6 +321,7 @@ function Update-Globals() {
301321
$Global:HealthyVMs = [System.Collections.ArrayList]@()
302322
$Global:UnHealthyVMs = [System.Collections.ArrayList]@()
303323
$Global:NotSupportedVMs = [System.Collections.ArrayList]@()
324+
$Global:LightweightVMs = [System.Collections.ArrayList]@()
304325
$Global:FailedVMs = [System.Collections.ArrayList]@()
305326
$Global:LogFile = "SqlVMsFailedToGetExtensionHealthDueToError" + $timestamp + ".log"
306327
$Global:ReportFile = "SqlVirtualMachinesExtensionHealthReport" + $timestamp + ".txt"
@@ -354,6 +375,12 @@ function new-Report() {
354375
$txtNotSupported = "Number of VMs having older extension version (extension health check not supported) : $($Global:NotSupportedVMs.Count)"
355376
show-VMDetailsInReport -Message $txtNotSupported -VMList $Global:NotSupportedVMs
356377
}
378+
379+
#display Lightweight VMs for which Extension is not deployed
380+
if ($Global:LightweightVMs.Count -gt 0) {
381+
$txtLightweightVMs = "Number of VMs Extension is not in operation (Lightweight VMs) : $($Global:LightweightVMs.Count)"
382+
show-VMDetailsInReport -Message $txtLightweightVMs -VMList $Global:LightweightVMs
383+
}
357384

358385
#display VMs for which failed to get Extension status
359386
if ($Global:FailedVMs.Count -gt 0) {
@@ -435,7 +462,14 @@ function new-ReportHelper(
435462

436463
foreach ($vm in $VmArray) {
437464
$outputObject = $outputObjectTemplate | Select-Object *
465+
if ($PSVersionTable.PSVersion.Major -eq 7)
466+
{
467+
$outputObject.Subscription = $vm.id.Split("/")[2]
468+
}
469+
elseif ($PSVersionTable.PSVersion.Major -eq 5)
470+
{
438471
$outputObject.Subscription = $vm.ResourceId.Split("/")[2]
472+
}
439473
$outputObject.ResourceGroup = $vm.ResourceGroupName
440474
$outputObject.VmName = $vm.Name
441475
$tmp = $outputObjectList.Add($outputObject)
@@ -468,10 +502,10 @@ function Get-ExtensionHealthStatusOfSingleVM(
468502
$tmp = $Global:Error.Clear()
469503
$tmp = (Get-AzVM -ResourceGroupName $ResourceGroup -Name $VmName -Status -ErrorAction SilentlyContinue).Extensions | Where-Object { $_.Name -eq 'SqlIaasExtension' }
470504

471-
$extVersion = $tmp.TypeHandlerVersion
505+
$extVersion = $tmp.TypeHandlerVersion
472506
if ($tmp -eq $null -or $tmp -eq "" -or $extVersion -eq $null) {
473507
return "Failed to retrieve health status"
474-
}
508+
}
475509

476510
if (-not (Assert-ExtensionVersion -extVersion $extVersion)) {
477511
return "Not supported Extension version"
@@ -480,9 +514,14 @@ function Get-ExtensionHealthStatusOfSingleVM(
480514
# Read ExtensionServiceHealthReport from SqlIaasExtension status
481515
$RPPluginReport = $tmp.SubStatuses | Where-Object { $_.Code -like '*Resource Provider Plugin*' } | Select-Object -ExpandProperty Message | ConvertFrom-Json
482516

483-
$MainServiceLastReportedTime = $RPPluginReport.ExtensionServiceHealthReport.MainServiceLastReportedTime
517+
$IsSqlManagement = $RPPluginReport.IsSqlManagement
518+
$MainServiceLastReportedTime = $RPPluginReport.ExtensionServiceHealthReport.MainServiceLastReportedTime
484519
$QueryServiceHealthStatus = $RPPluginReport.ExtensionServiceHealthReport.QueryServiceHealthStatus
485520

521+
if ($IsSqlManagement -eq $false) {
522+
return "Lightweight VM"
523+
}
524+
486525
# Get the current UTC time for comparison
487526
$utcTime = [System.DateTime]::UtcNow
488527
$utcTimeMinus1Hour = $utcTime.AddHours(-1)

0 commit comments

Comments
 (0)