@@ -46,7 +46,7 @@ function Get-SqlDscInstalledComponent
4646
4747 Assert-ElevatedUser - ErrorAction ' Stop'
4848
49- $installedComponents = @ ()
49+ $serviceComponent = @ ()
5050
5151 $currentInstalledServices = Get-SqlDscManagedComputerService - ServerName $ServerName - ErrorAction ' Stop'
5252
@@ -87,7 +87,7 @@ function Get-SqlDscInstalledComponent
8787 command does not use advanced properties, e.g:
8888 ($installedService.AdvancedProperties | ? Name -eq 'InstanceId').Value
8989 #>
90- $serviceComponent = [PSCustomObject ] @ {
90+ $serviceComponent + = [PSCustomObject ] @ {
9191 ServiceName = $installedService.Name
9292 ServiceType = $serviceType
9393 ServiceDisplayName = $installedService.DisplayName
@@ -100,99 +100,132 @@ function Get-SqlDscInstalledComponent
100100 InstanceId = $null
101101 Feature = @ ()
102102 }
103-
104- $installedComponents += $serviceComponent
105103 }
106104
107- # Loop to set InstanceId .
108- foreach ($component in $installedComponents .Where ({ $_.ServiceType -in (' DatabaseEngine' , ' AnalysisServices' , ' ReportingServices' ) }))
105+ # Get InstanceId for all installed services .
106+ foreach ($component in $serviceComponent .Where ({ $_.ServiceType -in (' DatabaseEngine' , ' AnalysisServices' , ' ReportingServices' ) }))
109107 {
110108 $component.InstanceId = $component.ServiceType | Get-InstanceId - InstanceName $component.InstanceName
111109 }
112110
113- # Loop to get features.
114- foreach ($component in $installedComponents )
111+ $installedComponents = @ ()
112+
113+ # Evaluate features based on installed services.
114+ foreach ($currentServiceComponent in $serviceComponent )
115115 {
116- switch ($component.ServiceType )
116+ $installedComponent = [PSCustomObject ] @ {
117+ Feature = $null
118+ }
119+
120+ switch ($currentServiceComponent.ServiceType )
117121 {
118122 ' DatabaseEngine'
119123 {
120- $component.Feature += ' SQLEngine'
121-
122- # $isReplicationInstalled = Test-IsReplicationFeatureInstalled -InstanceName $InstanceName
123-
124- if ($isReplicationInstalled )
125- {
126- $component.Feature += ' Replication'
127- }
128-
129- # $isDQInstalled = Test-IsDQComponentInstalled -InstanceName $InstanceName -SqlServerMajorVersion $sqlVersion
130-
131- if ($isDQInstalled )
132- {
133- $component.Feature += ' DQ'
134- }
135-
136- # TODO: This has nothing to do with DatabaseEngine.
137- $isDQInstalled = Test-IsDataQualityClientInstalled - Version $component.Version
138-
139- if ($isDQInstalled )
140- {
141- $component.Feature += ' DQC'
142- }
143-
144- # $isSsmsInstalled = Test-IsSsmsInstalled -SqlServerMajorVersion $sqlVersion
145-
146- if ($isSsmsInstalled )
147- {
148- $component.Feature += ' SSMS'
149- }
150-
151- # $isSsmsAdvancedInstalled = Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion $sqlVersion
152-
153- if ($isSsmsAdvancedInstalled )
154- {
155- $component.Feature += ' ADV_SSMS'
156- }
124+ $installedComponent.Feature = ' SQLEngine'
157125
158126 break
159127 }
160128
161129 ' 9'
162130 {
163- $component .Feature += ' FullText'
131+ $installedComponent .Feature += ' FullText'
164132
165133 break
166134 }
167135
168136 ' 12'
169137 {
170- $component .Feature += ' AdvancedAnalytics'
138+ $installedComponent .Feature += ' AdvancedAnalytics'
171139
172140 break
173141 }
174142
175143 ' AnalysisServices'
176144 {
177- $component .Feature += ' AS'
145+ $installedComponent .Feature += ' AS'
178146
179147 break
180148 }
181149
182150 ' IntegrationServices'
183151 {
184- $component .Feature += ' IS'
152+ $installedComponent .Feature += ' IS'
185153
186154 break
187155 }
188156
189157 ' ReportingServices'
190158 {
191- $component.Feature += ' RS'
159+ $installedComponent.Feature += ' RS'
160+
161+ break
162+ }
163+
164+ Default
165+ {
166+ # Skip services like SQL Browser and SQL Agent.
192167
193168 break
194169 }
195170 }
171+
172+ # Skip service if it wasn't detected as a feature.
173+ if ($installedComponent.Feature )
174+ {
175+ $installedComponent |
176+ Add-Member - MemberType ' NoteProperty' - Name ' InstanceName' - Value $currentServiceComponent.InstanceName - PassThru |
177+ Add-Member - MemberType ' NoteProperty' - Name ' InstanceId' - Value $currentServiceComponent.InstanceId - PassThru |
178+ Add-Member - MemberType ' NoteProperty' - Name ' Version' - Value $currentServiceComponent.ServiceExecutableVersion - PassThru |
179+ Add-Member - MemberType ' NoteProperty' - Name ' ServiceProperties' - Value $currentServiceComponent
180+
181+ $installedComponents += $installedComponent
182+ }
183+ }
184+
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+
199+ # Fetch registry keys that is three digits, like 100, 110, .., 160, and so on.
200+ $installedDatabaseLevel = (Split-Path - Leaf - Path (Get-ChildItem ' HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\' ).Name) -match ' ^\d\d\d$'
201+
202+ foreach ($databaseLevel in $installedDatabaseLevel )
203+ {
204+ $databaseLevelVersion = [System.Version ] (' {0}.{1}' -f $databaseLevel.Substring (0 , 2 ), $databaseLevel.Substring (2 , 1 ))
205+
206+ $isDQInstalled = Test-IsDataQualityClientInstalled - Version $databaseLevelVersion
207+
208+ if ($isDQInstalled )
209+ {
210+ $installedComponents += [PSCustomObject ] @ {
211+ Feature = ' DQC'
212+ Version = $databaseLevelVersion
213+ }
214+ }
215+ }
216+
217+ # $isSsmsInstalled = Test-IsSsmsInstalled -SqlServerMajorVersion $sqlVersion
218+
219+ if ($isSsmsInstalled )
220+ {
221+ $component.Feature = ' SSMS'
222+ }
223+
224+ # $isSsmsAdvancedInstalled = Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion $sqlVersion
225+
226+ if ($isSsmsAdvancedInstalled )
227+ {
228+ $component.Feature = ' ADV_SSMS'
196229 }
197230
198231
@@ -206,14 +239,14 @@ function Get-SqlDscInstalledComponent
206239 {
207240 $componentsToReturn += $installedComponents |
208241 Where-Object - FilterScript {
209- -not $_.InstanceName -and $_.FileProductVersion .Major -eq $Version.Major
242+ -not $_.InstanceName -and $_.Version .Major -eq $Version.Major
210243 }
211244 }
212245 else
213246 {
214247 $componentsToReturn += $installedComponents |
215248 Where-Object - FilterScript {
216- $_.FileProductVersion .Major -eq $Version.Major
249+ $_.Version .Major -eq $Version.Major
217250 }
218251 }
219252 }
0 commit comments