Skip to content

Commit e7003a9

Browse files
committed
Iteration 3
1 parent 1e9f573 commit e7003a9

5 files changed

Lines changed: 98 additions & 63 deletions
Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<#
22
.SYNOPSIS
3-
Returns the integration services settings.
3+
Returns the database engine settings.
44
55
.DESCRIPTION
6-
Returns the integration services settings.
6+
Returns the database engine settings.
77
8-
.PARAMETER Version
9-
Specifies the version for which to return settings for.
8+
.PARAMETER InstanceId
9+
Specifies the instance id on which to check if component is installed.
1010
1111
.OUTPUTS
1212
`[System.Management.Automation.PSCustomObject]`
1313
1414
.EXAMPLE
15-
Get-SqlDscIntegrationServicesSetting -Version ([System.Version] '16.0')
15+
Get-SqlDscDatabaseEngineSetting -InstanceId 'MSSQL13.SQL2016'
1616
17-
Returns the settings for the integration services.
17+
Returns the settings for the database engine.
1818
#>
1919
function Get-SqlDscDatabaseEngineSetting
2020
{
@@ -23,62 +23,36 @@ function Get-SqlDscDatabaseEngineSetting
2323
param
2424
(
2525
[Parameter(Mandatory = $true)]
26-
[System.Version]
27-
$Version
26+
[System.String]
27+
$InstanceId
2828
)
2929

30-
<#
31-
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL13.SQL2016\Setup
32-
33-
FeatureList
34-
Version
35-
PatchLevel
36-
Edition
37-
EditionType
38-
Language
39-
ProductCode
40-
SqlPath
41-
42-
TODO: Gör en Get-SqlDscServiceName med data från HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Services
43-
Liknande Get-SqlDscInstalledInstance
44-
#>
45-
$masterDataServicesSettings = $null
30+
$databaseEngineSettings = $null
4631

4732
$getItemPropertyParameters = @{
48-
Path = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{0}0\Master Data Services\Setup\MDSCoreFeature' -f $Version.Major
33+
Path = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{0}\Setup' -f $InstanceId
4934
ErrorAction = 'SilentlyContinue'
5035
}
5136

52-
$mdsCoreFeatureSettings = Get-ItemProperty @getItemPropertyParameters
37+
$setupSettings = Get-ItemProperty @getItemPropertyParameters
5338

54-
if (-not $mdsCoreFeatureSettings)
39+
if (-not $setupSettings)
5540
{
56-
$missingIntegrationServiceMessage = $script:localizedData.MasterDataServicesSetting_Get_NotInstalled -f $Version.ToString()
41+
$missingDatabaseEngineMessage = $script:localizedData.DatabaseEngineSetting_Get_NotInstalled -f $Version.ToString()
5742

5843
$writeErrorParameters = @{
59-
Message = $missingIntegrationServiceMessage
60-
Category = 'InvalidOperation'
61-
ErrorId = 'GISS0001' # cspell: disable-line
44+
Message = $missingDatabaseEngineMessage
45+
Category = 'InvalidOperation'
46+
ErrorId = 'GISS0001' # cspell: disable-line
6247
TargetObject = $Version
6348
}
6449

6550
Write-Error @writeErrorParameters
6651
}
6752
else
6853
{
69-
$masterDataServicesSettings1 = [InstalledComponentSetting]::Parse($mdsCoreFeatureSettings)
70-
71-
$getItemPropertyParameters = @{
72-
Path = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{0}0\Master Data Services\Setup' -f $Version.Major
73-
ErrorAction = 'SilentlyContinue'
74-
}
75-
76-
$mdsSetupSettings = Get-ItemProperty @getItemPropertyParameters
77-
78-
$masterDataServicesSettings2 = [InstalledComponentSetting]::Parse($mdsSetupSettings)
79-
80-
$masterDataServicesSettings = $masterDataServicesSettings1 + $masterDataServicesSettings2
54+
$databaseEngineSettings = [InstalledComponentSetting]::Parse($setupSettings)
8155
}
8256

83-
return $masterDataServicesSettings
57+
return $databaseEngineSettings
8458
}

source/Public/Get-SqlDscInstalledComponent.ps1

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ function Get-SqlDscInstalledComponent
5959

6060
switch ($currentServiceComponent.ServiceType)
6161
{
62-
# TODO: Add a Test-command for the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL13.SQL2016\ConfigurationState\SQL_Engine_Core_Inst
63-
'DatabaseEngine'
64-
{
65-
$installedComponent.Feature = 'SQLEngine'
66-
67-
break
68-
}
69-
7062
# TODO: Add a Test-command for the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL16.SQL2022\ConfigurationState\SQL_FullText_Adv
7163
'9'
7264
{
@@ -114,7 +106,7 @@ function Get-SqlDscInstalledComponent
114106
Add-Member -MemberType 'NoteProperty' -Name 'InstanceId' -Value (
115107
$currentServiceComponent.ServiceType |
116108
Get-InstanceId -InstanceName $currentServiceComponent.InstanceName
117-
)
109+
)
118110
}
119111

120112
$installedComponents += $installedComponent
@@ -232,16 +224,28 @@ function Get-SqlDscInstalledComponent
232224

233225
foreach ($currentInstance in $installedDatabaseEngineInstance)
234226
{
227+
# Look for installed version of Database Engine.
228+
$databaseEngineSettings = Get-SqlDscDatabaseEngineSetting -InstanceId $currentInstance.InstanceId -ErrorAction 'SilentlyContinue'
229+
230+
if ($databaseEngineSettings)
231+
{
232+
$installedComponents += [PSCustomObject] @{
233+
Feature = 'SQLENGINE'
234+
InstanceName = $currentInstance.InstanceName
235+
Version = $databaseEngineSettings.Version
236+
}
237+
}
238+
235239
# Looking for installed version for Replication.
236240
$isReplicationInstalled = Test-SqlDscIsReplicationInstalled -InstanceId $currentInstance.InstanceId
237241

238242
if ($isReplicationInstalled)
239243
{
240244
$installedComponents += [PSCustomObject] @{
241-
Feature = 'Replication'
245+
Feature = 'Replication'
242246
#Version = $currentInstance.Version
243247
InstanceName = $currentInstance.InstanceName
244-
InstanceId = $currentInstance.InstanceId
248+
InstanceId = $currentInstance.InstanceId
245249
}
246250
}
247251

@@ -251,10 +255,10 @@ function Get-SqlDscInstalledComponent
251255
if ($isReplicationInstalled)
252256
{
253257
$installedComponents += [PSCustomObject] @{
254-
Feature = 'AdvancedAnalytics'
258+
Feature = 'AdvancedAnalytics'
255259
#Version = $currentInstance.Version
256260
InstanceName = $currentInstance.InstanceName
257-
InstanceId = $currentInstance.InstanceId
261+
InstanceId = $currentInstance.InstanceId
258262
}
259263
}
260264

@@ -263,10 +267,10 @@ function Get-SqlDscInstalledComponent
263267
if ($isDataQualityServerInstalled)
264268
{
265269
$installedComponents += [PSCustomObject] @{
266-
Feature = 'DQ'
270+
Feature = 'DQ'
267271
#Version = $currentInstance.Version
268272
InstanceName = $currentInstance.InstanceName
269-
InstanceId = $currentInstance.InstanceId
273+
InstanceId = $currentInstance.InstanceId
270274
}
271275
}
272276

@@ -275,10 +279,10 @@ function Get-SqlDscInstalledComponent
275279
if ($isROpenRPackagesInstalled)
276280
{
277281
$installedComponents += [PSCustomObject] @{
278-
Feature = 'SQL_INST_MR'
282+
Feature = 'SQL_INST_MR'
279283
#Version = $currentInstance.Version
280284
InstanceName = $currentInstance.InstanceName
281-
InstanceId = $currentInstance.InstanceId
285+
InstanceId = $currentInstance.InstanceId
282286
}
283287
}
284288
}

source/Public/Get-SqlDscMasterDataServicesSetting.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ function Get-SqlDscMasterDataServicesSetting
3838

3939
if (-not $mdsCoreFeatureSettings)
4040
{
41-
$missingIntegrationServiceMessage = $script:localizedData.MasterDataServicesSetting_Get_NotInstalled -f $Version.ToString()
41+
$missingMasterDataServicesMessage = $script:localizedData.MasterDataServicesSetting_Get_NotInstalled -f $Version.ToString()
4242

4343
$writeErrorParameters = @{
44-
Message = $missingIntegrationServiceMessage
44+
Message = $missingMasterDataServicesMessage
4545
Category = 'InvalidOperation'
4646
ErrorId = 'GISS0001' # cspell: disable-line
4747
TargetObject = $Version
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<#
2+
.SYNOPSIS
3+
Returns all the registered service types.
4+
5+
.DESCRIPTION
6+
Returns all the registered service types.
7+
8+
.OUTPUTS
9+
`[System.Object[]]`
10+
11+
.EXAMPLE
12+
Get-SqlDscServiceType
13+
14+
Returns all service types.
15+
#>
16+
function Get-SqlDscServiceType
17+
{
18+
[CmdletBinding()]
19+
[OutputType([System.Object[]])]
20+
param ()
21+
22+
$registeredServiceTypes = @()
23+
24+
$registeredServiceType = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Services'
25+
26+
foreach ($currentServiceType in $registeredServiceType)
27+
{
28+
$foundServiceType = [PSCustomObject]@{
29+
DisplayName = $currentServiceType.PSChildName
30+
}
31+
32+
$properties = $currentServiceType.GetValueNames()
33+
34+
foreach ($property in $properties)
35+
{
36+
$foundServiceType |
37+
Add-Member -MemberType 'NoteProperty' -Name $property -Value $currentServiceType.GetValue($property)
38+
}
39+
40+
$managedServiceType = [Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]::Parse([Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType], $currentServiceType.GetValue('Type'))
41+
42+
$foundServiceType |
43+
Add-Member -MemberType 'NoteProperty' -Name 'ManagedServiceType' -Value $managedServiceType
44+
45+
$foundServiceType |
46+
Add-Member -MemberType 'NoteProperty' -Name 'NormalizedServiceType' -Value (
47+
ConvertFrom-ManagedServiceType -ServiceType $managedServiceType -ErrorAction 'SilentlyContinue'
48+
)
49+
50+
$registeredServiceTypes += $foundServiceType
51+
}
52+
53+
return $registeredServiceTypes
54+
}

source/en-US/SqlServerDsc.strings.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,7 @@ ConvertFrom-StringData @'
193193
194194
## Get-SqlDscMasterDataServicesSetting
195195
MasterDataServicesSetting_Get_NotInstalled = There are no Master Data Services installed with version {0}.
196+
197+
## Get-SqlDscDatabaseEngineSetting
198+
DatabaseEngineSetting_Get_NotInstalled = There are no Database Engine installed with version {0}.
196199
'@

0 commit comments

Comments
 (0)