Skip to content

Commit 2f5caf5

Browse files
committed
Added PS Script to get the SQL Reclass & extension status
1 parent 062d005 commit 2f5caf5

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# This script return a report of the instances that should return SQL Reclass from the Azure Arc servers perspective
2+
# It also returns all the extension status from Arc Servers that has mssqldiscovered to true
3+
4+
#region Sample queries
5+
6+
# Get SQL Azure Arc Servers
7+
$queryArcSQLServers = @"
8+
resources
9+
| where type =~ 'microsoft.hybridcompute/machines'
10+
| where properties.detectedProperties.mssqldiscovered == "true"
11+
"@
12+
13+
# Get SQL Instances
14+
$queryArcSQLServerinstances = @'
15+
resources
16+
| where ['type'] == "microsoft.azurearcdata/sqlserverinstances"
17+
| project containerResourceId = properties.containerResourceId, instanceName = properties.instanceName, edition = properties.edition, version = properties.version, licenseType = properties.licenseType
18+
'@
19+
#Get SQL Instances
20+
$queryArcServerextensions = @"
21+
resources
22+
| where type == 'microsoft.hybridcompute/machines/extensions'
23+
| where properties.type == "WindowsAgent.SqlServer"
24+
"@
25+
#endregion
26+
27+
28+
#region Report of servers generating SQL Reclass
29+
# The following query returns all the SQL Enterprise and Standard Instances, whose Azure Arc server exists and it is not in Expired State
30+
# The query returns the created time, version, licensetype and vcores
31+
$queryglobal = @"
32+
resources
33+
| where type in ('microsoft.hybridcompute/machines')
34+
| extend Status = properties.status, id = tolower(id), AzureArcServerName = name
35+
| where properties.status != "Expired"
36+
| join kind = fullouter
37+
(resources
38+
| where type == 'microsoft.hybridcompute/machines/extensions'
39+
| where properties.type == "WindowsAgent.SqlServer"
40+
| project id=tolower(id),AzureArcServerid = tolower(tostring(split(id,'/extensions/',0)[0])), ExVersion = properties.typeHandlerVersion, provisioningState = tostring(properties.provisioningState)
41+
| order by provisioningState) on `$left.['id'] == `$right.AzureArcServerid
42+
| join kind=inner (
43+
resources
44+
| where type =~ "Microsoft.AzureArcData/sqlServerInstances"
45+
| extend edition = tostring(properties.edition)
46+
| where edition in ('Standard','Enterprise')
47+
| extend AzureArcServerid = tolower(tostring(properties.containerResourceId))
48+
| extend SQLInstanceName = name
49+
| extend createdAt = format_datetime(todatetime(systemData.createdAt), 'yyyy-MM-dd hh:mm:ss')
50+
| extend version = tostring(properties.version)
51+
| extend licenseType = tostring(properties.licenseType)
52+
| extend vcores = toint(properties.vCore)) on AzureArcServerid
53+
| where isnotempty(['id'])
54+
| project createdAt,subscriptionId,resourceGroup,AzureArcServerName,Status,SQLInstanceName,version,edition,vcores,licenseType,ExVersion,provisioningState
55+
"@
56+
57+
#KQL Global Query results
58+
Write-Host "Querying servers that are generating SQL Reclass .. `n" -ForegroundColor Green
59+
$ResultsGlobal = Search-AzGraph -Query $queryglobal -First 1000
60+
61+
62+
# View LicenseType property directly from Azure Arc Extension and merge the data in a single table
63+
64+
Write-Host "Querying extension using powershell. This might take a while .. `n" -ForegroundColor Green
65+
$ResultsGlobalGrouped = $ResultsGlobal | Group-Object -Property subscriptionid
66+
$results = foreach ($group in $ResultsGlobalGrouped) {
67+
#Get-AzSubscription -SubscriptionId $group.Name -WarningAction SilentlyContinue
68+
$Subscription = Select-AzSubscription -SubscriptionId $group.Name -WarningAction SilentlyContinue
69+
Write-Host "Getting SQL extension information from Subscription:" -ForegroundColor Green
70+
Write-Host "$($Subscription.Subscription.Name) $($Subscription.Subscription.id)" -ForegroundColor Yellow
71+
foreach ($arcobject in $group.Group ) {
72+
$machinename = $arcobject.AzureArcServerName
73+
$ResourceGroupName = $arcobject.resourceGroup
74+
$licensetype = Get-AzConnectedMachineExtension -MachineName $machinename -ResourceGroupName $ResourceGroupName -Name WindowsAgent.SqlServer -ErrorAction SilentlyContinue | Select-Object -ExpandProperty setting | ConvertFrom-Json | Select-Object -ExpandProperty LicenseType -ErrorAction SilentlyContinue
75+
$properties = [ordered]@{
76+
createdAt = $arcobject.createdAt
77+
subscriptionId = $arcobject.subscriptionId
78+
resourceGroup = $arcobject.resourceGroup
79+
AzureArcServerName = $arcobject.AzureArcServerName
80+
Status = $arcobject.Status
81+
SQLInstanceName = $arcobject.SQLInstanceName
82+
version = $arcobject.version
83+
edition = $arcobject.edition
84+
vcores = $arcobject.vcores
85+
licenseTypeinGraph = $arcobject.licenseType
86+
licenseTypeInExt = $licensetype
87+
ExVersion = $arcobject.ExVersion
88+
provisioningState = $arcobject.provisioningState
89+
90+
}
91+
New-Object -TypeName psobject -Property $properties
92+
93+
}
94+
}
95+
# Variable $results contains all the info
96+
97+
# The following exports in a CSV file the servers that are effectively generating ACR (2008 is not suported)
98+
$global:ArcSQLServerinstanceswithReclass = $results | where version -notlike *2008*
99+
$ArcSQLServerinstanceswithReclass | Export-Csv -Path .\ArcSQLServerinstanceswithReclass.csv -Force
100+
Write-Host "Results where exported to file 'ArcSQLServerinstanceswithReclass.csv' in the local folder" -ForegroundColor Green
101+
#endregion
102+
103+
###############################
104+
105+
#region Report of SQL extension Status
106+
107+
# The following query returns all the SQL extensions from servers that has mssqldiscovered set to True
108+
# The query returns the Arc Server with its subscription, resource group, status, extension version and provisioning state
109+
110+
$queryExtensionSatus = @"
111+
resources
112+
| where type =~ 'microsoft.hybridcompute/machines'
113+
| where properties.detectedProperties.mssqldiscovered == "true"
114+
| extend id = tolower(id), ResourceGroup = split (id,'/',8)[0], Status = properties.status
115+
| join kind = inner (resources
116+
| where type == 'microsoft.hybridcompute/machines/extensions'
117+
| where properties.type == "WindowsAgent.SqlServer"
118+
| extend provisioningState = tostring(properties.provisioningState), ExVersion = properties.typeHandlerVersion
119+
| extend AzureArcServerid = tolower(tostring(split(id,'/extensions/',0)[0]))) on `$left.id == `$right.AzureArcServerid
120+
| project subscriptionId,ResourceGroup,name,Status,ExVersion,provisioningState
121+
| order by ['provisioningState'] asc
122+
"@
123+
124+
Write-Host "`nQuerying status of the SQL Extensions in azure Arc servers .. `n" -ForegroundColor Green
125+
$global:SQLExtensionStatus = Search-AzGraph -Query $queryExtensionSatus -First 1000
126+
127+
# The following exports in a CSV file the status of the SQL extension in the Azure Arc Servers
128+
$SQLExtensionStatus | Export-Csv -Path .\SQLExtensionStatus.csv -Force
129+
Write-Host "Results where exported to file 'SQLExtensionStatus.csv' in the local folder" -ForegroundColor Green
130+
131+

0 commit comments

Comments
 (0)