Skip to content

Commit ec52402

Browse files
committed
Fix more commands to test current state
1 parent e26f69c commit ec52402

10 files changed

Lines changed: 553 additions & 86 deletions

source/Public/Get-SqlDscInstalledComponent.ps1

Lines changed: 121 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -46,67 +46,7 @@ function Get-SqlDscInstalledComponent
4646

4747
Assert-ElevatedUser -ErrorAction 'Stop'
4848

49-
$serviceComponent = @()
50-
51-
$currentInstalledServices = Get-SqlDscManagedComputerService -ServerName $ServerName -ErrorAction 'Stop'
52-
53-
foreach ($installedService in $currentInstalledServices)
54-
{
55-
$serviceType = $installedService.Type | ConvertFrom-ManagedServiceType -ErrorAction 'SilentlyContinue'
56-
57-
if (-not $serviceType)
58-
{
59-
<#
60-
This is a workaround because [Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]
61-
does not support all service types yet.
62-
#>
63-
$serviceType = $installedService.Type
64-
}
65-
66-
$fileProductVersion = $null
67-
68-
$serviceExecutablePath = (($installedService.PathName -replace '"') -split ' -')[0]
69-
70-
if ((Test-Path -Path $serviceExecutablePath))
71-
{
72-
$fileProductVersion = [System.Version] (Get-FileVersionInformation -FilePath $serviceExecutablePath).ProductVersion
73-
}
74-
75-
# Get InstanceName from the service name if it exist.
76-
$serviceInstanceName = if ($installedService.Name -match '\$(.*)$')
77-
{
78-
$Matches[1]
79-
}
80-
81-
$serviceStartMode = $installedService.StartMode | ConvertFrom-ServiceStartMode
82-
83-
<#
84-
There are more properties that can be fetch from advanced properties,
85-
for example InstanceId, Clustered, and Version (for some), but it takes
86-
about 6 seconds for it to return a value. Because of the slowness this
87-
command does not use advanced properties, e.g:
88-
($installedService.AdvancedProperties | ? Name -eq 'InstanceId').Value
89-
#>
90-
$serviceComponent += [PSCustomObject] @{
91-
ServiceName = $installedService.Name
92-
ServiceType = $serviceType
93-
ServiceDisplayName = $installedService.DisplayName
94-
ServiceAccountName = $installedService.ServiceAccount
95-
ServiceStartMode = $serviceStartMode
96-
InstanceName = $serviceInstanceName
97-
ServiceExecutableVersion = $fileProductVersion
98-
99-
# Properties that should be on all objects, but set later
100-
InstanceId = $null
101-
Feature = @()
102-
}
103-
}
104-
105-
# Get InstanceId for all installed services.
106-
foreach ($component in $serviceComponent.Where({ $_.ServiceType -in ('DatabaseEngine', 'AnalysisServices', 'ReportingServices') }))
107-
{
108-
$component.InstanceId = $component.ServiceType | Get-InstanceId -InstanceName $component.InstanceName
109-
}
49+
$serviceComponent = Get-SqlDscInstalledService -ServerName $ServerName
11050

11151
$installedComponents = @()
11252

@@ -174,35 +114,31 @@ function Get-SqlDscInstalledComponent
174114
{
175115
$installedComponent |
176116
Add-Member -MemberType 'NoteProperty' -Name 'InstanceName' -Value $currentServiceComponent.InstanceName -PassThru |
177-
Add-Member -MemberType 'NoteProperty' -Name 'InstanceId' -Value $currentServiceComponent.InstanceId -PassThru |
178117
Add-Member -MemberType 'NoteProperty' -Name 'Version' -Value $currentServiceComponent.ServiceExecutableVersion -PassThru |
179118
Add-Member -MemberType 'NoteProperty' -Name 'ServiceProperties' -Value $currentServiceComponent
180119

120+
# Get InstanceId for all installed services.
121+
if ($currentServiceComponent.ServiceType -in ('DatabaseEngine', 'AnalysisServices', 'ReportingServices'))
122+
{
123+
$installedComponent |
124+
Add-Member -MemberType 'NoteProperty' -Name 'InstanceId' -Value (
125+
$currentServiceComponent.ServiceType |
126+
Get-InstanceId -InstanceName $currentServiceComponent.InstanceName
127+
)
128+
}
129+
181130
$installedComponents += $installedComponent
182131
}
183132
}
184133

185-
#$isReplicationInstalled = Test-IsReplicationFeatureInstalled -InstanceName $InstanceName
186-
187-
if ($isReplicationInstalled)
188-
{
189-
$component.Feature = 'Replication'
190-
}
191-
192-
#$isDQInstalled = Test-IsDQComponentInstalled -InstanceName $InstanceName -SqlServerMajorVersion $sqlVersion
193-
194-
if ($isDQInstalled)
195-
{
196-
$component.Feature = 'DQ'
197-
}
198-
199134
# Fetch registry keys that is three digits, like 100, 110, .., 160, and so on.
200135
$installedDatabaseLevel = (Split-Path -Leaf -Path (Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\').Name) -match '^\d\d\d$'
201136

202137
foreach ($databaseLevel in $installedDatabaseLevel)
203138
{
204139
$databaseLevelVersion = [System.Version] ('{0}.{1}' -f $databaseLevel.Substring(0,2), $databaseLevel.Substring(2,1))
205140

141+
# Look for installed version of Data Quality Client.
206142
$isDQInstalled = Test-IsDataQualityClientInstalled -Version $databaseLevelVersion
207143

208144
if ($isDQInstalled)
@@ -212,22 +148,123 @@ function Get-SqlDscInstalledComponent
212148
Version = $databaseLevelVersion
213149
}
214150
}
215-
}
216151

217-
#$isSsmsInstalled = Test-IsSsmsInstalled -SqlServerMajorVersion $sqlVersion
152+
# Look for installed version of SQL Server Books Online.
153+
$isBOLInstalled = Test-IsBooksOnlineInstalled -Version $databaseLevelVersion
218154

219-
if ($isSsmsInstalled)
220-
{
221-
$component.Feature = 'SSMS'
155+
if ($isBOLInstalled)
156+
{
157+
$installedComponents += [PSCustomObject] @{
158+
Feature = 'BOL'
159+
Version = $databaseLevelVersion
160+
}
161+
}
162+
163+
# Look for installed version of Connectivity Components.
164+
$isConnInstalled = Test-IsConnectivityComponentsInstalled -Version $databaseLevelVersion
165+
166+
if ($isConnInstalled)
167+
{
168+
$installedComponents += [PSCustomObject] @{
169+
Feature = 'CONN'
170+
Version = $databaseLevelVersion
171+
}
172+
}
173+
174+
# Look for installed version of Backward Compatibility Components.
175+
$isBCInstalled = Test-IsBackwardCompatibilityComponentsInstalled -Version $databaseLevelVersion
176+
177+
if ($isBCInstalled)
178+
{
179+
$installedComponents += [PSCustomObject] @{
180+
Feature = 'BC'
181+
Version = $databaseLevelVersion
182+
}
183+
}
184+
185+
# Look for installed version of Software Development Kit.
186+
$isSDKInstalled = Test-IsSoftwareDevelopmentKitInstalled -Version $databaseLevelVersion
187+
188+
if ($isSDKInstalled)
189+
{
190+
$installedComponents += [PSCustomObject] @{
191+
Feature = 'SDK'
192+
Version = $databaseLevelVersion
193+
}
194+
}
195+
196+
# Look for installed version of Master Data Services.
197+
$isMDSInstalled = Test-IsMasterDataServicesInstalled -Version $databaseLevelVersion
198+
199+
if ($isMDSInstalled)
200+
{
201+
$installedComponents += [PSCustomObject] @{
202+
Feature = 'MDS'
203+
Version = $databaseLevelVersion
204+
}
205+
}
222206
}
223207

224-
#$isSsmsAdvancedInstalled = Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion $sqlVersion
208+
$databaseEngineInstance = $installedComponents |
209+
Where-Object -FilterScript {
210+
$_.InstanceId -match '^MSSQL'
211+
}
225212

226-
if ($isSsmsAdvancedInstalled)
213+
foreach ($currentInstance in $databaseEngineInstance)
227214
{
228-
$component.Feature = 'ADV_SSMS'
215+
# Looking for installed version for Replication.
216+
$isReplicationInstalled = Test-IsReplicationInstalled -InstanceId $currentInstance.InstanceId
217+
218+
if ($isReplicationInstalled)
219+
{
220+
$installedComponents += [PSCustomObject] @{
221+
Feature = 'Replication'
222+
Version = $currentInstance.Version
223+
InstanceName = $currentInstance.InstanceName
224+
InstanceId = $currentInstance.InstanceId
225+
}
226+
}
227+
228+
# Looking for installed version for Replication.
229+
$isReplicationInstalled = Test-IsAdvancedAnalyticsInstalled -InstanceId $currentInstance.InstanceId
230+
231+
if ($isReplicationInstalled)
232+
{
233+
$installedComponents += [PSCustomObject] @{
234+
Feature = 'AdvancedAnalytics'
235+
Version = $currentInstance.Version
236+
InstanceName = $currentInstance.InstanceName
237+
InstanceId = $currentInstance.InstanceId
238+
}
239+
}
229240
}
230241

242+
# SQL_DQ_Full = DQ : Data Quality Services
243+
# sql_inst_mr = SQL_INST_MR : R Open and proprietary R packages
244+
# sql_inst_mpy = SQL_INST_MPY : Anaconda and proprietary Python packages.
245+
# SQL_Polybase_Core_Inst = PolyBaseCore : PolyBase technology
246+
247+
#$isDQInstalled = Test-IsDQComponentInstalled -InstanceName $InstanceName -SqlServerMajorVersion $sqlVersion
248+
249+
# if ($isDQInstalled)
250+
# {
251+
# $component.Feature = 'DQ'
252+
# }
253+
254+
# #$isSsmsInstalled = Test-IsSsmsInstalled -SqlServerMajorVersion $sqlVersion
255+
256+
# if ($isSsmsInstalled)
257+
# {
258+
# $component.Feature = 'SSMS'
259+
# }
260+
261+
# #$isSsmsAdvancedInstalled = Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion $sqlVersion
262+
263+
# if ($isSsmsAdvancedInstalled)
264+
# {
265+
# $component.Feature = 'ADV_SSMS'
266+
# }
267+
231268

232269
# Filter result
233270

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<#
2+
.SYNOPSIS
3+
Returns an installed Microsoft SQL Server component that runs as a service.
4+
5+
.DESCRIPTION
6+
Returns an installed Microsoft SQL Server component that runs as a service.
7+
8+
.PARAMETER ServerName
9+
Specifies the server name to return the components from.
10+
11+
.EXAMPLE
12+
Get-SqlDscInstalledComponents
13+
14+
Returns all the installed services.
15+
16+
.OUTPUTS
17+
`[System.Management.Automation.PSCustomObject]`
18+
#>
19+
function Get-SqlDscInstalledService
20+
{
21+
[OutputType([System.Management.Automation.PSCustomObject])]
22+
[CmdletBinding()]
23+
param
24+
(
25+
[Parameter()]
26+
[ValidateNotNullOrEmpty()]
27+
[System.String]
28+
$ServerName = (Get-ComputerName),
29+
30+
[Parameter()]
31+
[System.String]
32+
$InstanceName,
33+
34+
[Parameter()]
35+
[System.Version]
36+
$Version
37+
)
38+
39+
Assert-ElevatedUser -ErrorAction 'Stop'
40+
41+
$serviceComponent = @()
42+
43+
$currentInstalledServices = Get-SqlDscManagedComputerService -ServerName $ServerName -ErrorAction 'Stop'
44+
45+
foreach ($installedService in $currentInstalledServices)
46+
{
47+
$serviceType = $installedService.Type | ConvertFrom-ManagedServiceType -ErrorAction 'SilentlyContinue'
48+
49+
if (-not $serviceType)
50+
{
51+
<#
52+
This is a workaround because [Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]
53+
does not support all service types yet.
54+
#>
55+
$serviceType = $installedService.Type
56+
}
57+
58+
$fileProductVersion = $null
59+
60+
$serviceExecutablePath = (($installedService.PathName -replace '"') -split ' -')[0]
61+
62+
if ((Test-Path -Path $serviceExecutablePath))
63+
{
64+
$fileProductVersion = [System.Version] (Get-FileVersionInformation -FilePath $serviceExecutablePath).ProductVersion
65+
}
66+
67+
# Get InstanceName from the service name if it exist.
68+
$serviceInstanceName = if ($installedService.Name -match '\$(.*)$')
69+
{
70+
$Matches[1]
71+
}
72+
73+
$serviceStartMode = $installedService.StartMode | ConvertFrom-ServiceStartMode
74+
75+
<#
76+
There are more properties that can be fetch from advanced properties,
77+
for example InstanceId, Clustered, and Version (for some), but it takes
78+
about 6 seconds for it to return a value. Because of the slowness this
79+
command does not use advanced properties, e.g:
80+
($installedService.AdvancedProperties | ? Name -eq 'InstanceId').Value
81+
#>
82+
$serviceComponent += [PSCustomObject] @{
83+
ServiceName = $installedService.Name
84+
ServiceType = $serviceType
85+
ServiceDisplayName = $installedService.DisplayName
86+
ServiceAccountName = $installedService.ServiceAccount
87+
ServiceStartMode = $serviceStartMode
88+
InstanceName = $serviceInstanceName
89+
ServiceExecutableVersion = $fileProductVersion
90+
}
91+
}
92+
93+
return $serviceComponent
94+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<#
2+
.SYNOPSIS
3+
Returns whether the component Advanced Analytics is installed.
4+
5+
.DESCRIPTION
6+
Returns whether the component Advanced Analytics is installed.
7+
8+
.PARAMETER InstanceId
9+
Specifies the instance id on which to check if component is installed.
10+
11+
.OUTPUTS
12+
[System.Boolean]
13+
14+
.EXAMPLE
15+
Test-IsReplicationInstalled -InstanceId 'MSSQL16.SQL2022'
16+
17+
Returns $true if Advanced Analytics is installed.
18+
#>
19+
function Test-IsAdvancedAnalyticsInstalled
20+
{
21+
[CmdletBinding()]
22+
[OutputType([System.Boolean])]
23+
param
24+
(
25+
[Parameter()]
26+
[System.String]
27+
$InstanceId
28+
)
29+
30+
$configurationStateRegistryPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{0}\ConfigurationState'
31+
32+
$getRegistryPropertyValueParameters = @{
33+
Path = $configurationStateRegistryPath -f $InstanceId
34+
Name = 'AdvancedAnalytics'
35+
ErrorAction = 'SilentlyContinue'
36+
}
37+
38+
$isAdvancedAnalyticsInstalled = Get-RegistryPropertyValue @getRegistryPropertyValueParameters
39+
40+
$result = $false
41+
42+
if ($isAdvancedAnalyticsInstalled -eq 1)
43+
{
44+
$result = $true
45+
}
46+
47+
return $result
48+
}

0 commit comments

Comments
 (0)