@@ -131,12 +131,28 @@ function Get-SqlVmList() {
131
131
$vmList = [System.Collections.ArrayList ]@ ()
132
132
133
133
$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
+
135
138
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*' )) {
137
151
$tmp = $vmList.Add ($vm )
152
+ }
138
153
}
139
154
}
155
+
140
156
return , $vmList
141
157
}
142
158
@@ -186,6 +202,9 @@ function Get-SqlVmExtensionStatusFromList(
186
202
}
187
203
' Not supported Extension version' {
188
204
$tmp = $Global :NotSupportedVMs.Add ($vm )
205
+ }
206
+ ' Lightweight VM' {
207
+ $tmp = $Global :LightweightVMs.Add ($vm )
189
208
}
190
209
Default {
191
210
$tmp = $Global :FailedVMs.Add ($vm )
@@ -286,6 +305,7 @@ $Global:SubscriptionsFailedToConnect = [System.Collections.ArrayList]@()
286
305
$Global :HealthyVMs = [System.Collections.ArrayList ]@ ()
287
306
$Global :UnHealthyVMs = [System.Collections.ArrayList ]@ ()
288
307
$Global :NotSupportedVMs = [System.Collections.ArrayList ]@ ()
308
+ $Global :LightweightVMs = [System.Collections.ArrayList ]@ ()
289
309
$Global :FailedVMs = [System.Collections.ArrayList ]@ ()
290
310
$Global :LogFile = $null
291
311
$Global :ReportFile = $null
@@ -301,6 +321,7 @@ function Update-Globals() {
301
321
$Global :HealthyVMs = [System.Collections.ArrayList ]@ ()
302
322
$Global :UnHealthyVMs = [System.Collections.ArrayList ]@ ()
303
323
$Global :NotSupportedVMs = [System.Collections.ArrayList ]@ ()
324
+ $Global :LightweightVMs = [System.Collections.ArrayList ]@ ()
304
325
$Global :FailedVMs = [System.Collections.ArrayList ]@ ()
305
326
$Global :LogFile = " SqlVMsFailedToGetExtensionHealthDueToError" + $timestamp + " .log"
306
327
$Global :ReportFile = " SqlVirtualMachinesExtensionHealthReport" + $timestamp + " .txt"
@@ -354,6 +375,12 @@ function new-Report() {
354
375
$txtNotSupported = " Number of VMs having older extension version (extension health check not supported) : $ ( $Global :NotSupportedVMs.Count ) "
355
376
show-VMDetailsInReport - Message $txtNotSupported - VMList $Global :NotSupportedVMs
356
377
}
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
+ }
357
384
358
385
# display VMs for which failed to get Extension status
359
386
if ($Global :FailedVMs.Count -gt 0 ) {
@@ -435,7 +462,14 @@ function new-ReportHelper(
435
462
436
463
foreach ($vm in $VmArray ) {
437
464
$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
+ {
438
471
$outputObject.Subscription = $vm.ResourceId.Split (" /" )[2 ]
472
+ }
439
473
$outputObject.ResourceGroup = $vm.ResourceGroupName
440
474
$outputObject.VmName = $vm.Name
441
475
$tmp = $outputObjectList.Add ($outputObject )
@@ -468,10 +502,10 @@ function Get-ExtensionHealthStatusOfSingleVM(
468
502
$tmp = $Global :Error.Clear ()
469
503
$tmp = (Get-AzVM - ResourceGroupName $ResourceGroup - Name $VmName - Status - ErrorAction SilentlyContinue).Extensions | Where-Object { $_.Name -eq ' SqlIaasExtension' }
470
504
471
- $extVersion = $tmp.TypeHandlerVersion
505
+ $extVersion = $tmp.TypeHandlerVersion
472
506
if ($tmp -eq $null -or $tmp -eq " " -or $extVersion -eq $null ) {
473
507
return " Failed to retrieve health status"
474
- }
508
+ }
475
509
476
510
if (-not (Assert-ExtensionVersion - extVersion $extVersion )) {
477
511
return " Not supported Extension version"
@@ -480,9 +514,14 @@ function Get-ExtensionHealthStatusOfSingleVM(
480
514
# Read ExtensionServiceHealthReport from SqlIaasExtension status
481
515
$RPPluginReport = $tmp.SubStatuses | Where-Object { $_.Code -like ' *Resource Provider Plugin*' } | Select-Object - ExpandProperty Message | ConvertFrom-Json
482
516
483
- $MainServiceLastReportedTime = $RPPluginReport.ExtensionServiceHealthReport.MainServiceLastReportedTime
517
+ $IsSqlManagement = $RPPluginReport.IsSqlManagement
518
+ $MainServiceLastReportedTime = $RPPluginReport.ExtensionServiceHealthReport.MainServiceLastReportedTime
484
519
$QueryServiceHealthStatus = $RPPluginReport.ExtensionServiceHealthReport.QueryServiceHealthStatus
485
520
521
+ if ($IsSqlManagement -eq $false ) {
522
+ return " Lightweight VM"
523
+ }
524
+
486
525
# Get the current UTC time for comparison
487
526
$utcTime = [System.DateTime ]::UtcNow
488
527
$utcTimeMinus1Hour = $utcTime.AddHours (-1 )
0 commit comments