Skip to content

Commit

Permalink
Iteration 3
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Jun 18, 2023
1 parent 2f68b2a commit e0af130
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 63 deletions.
62 changes: 18 additions & 44 deletions source/Public/Get-SqlDscDatabaseEngineSetting.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<#
.SYNOPSIS
Returns the integration services settings.
Returns the database engine settings.
.DESCRIPTION
Returns the integration services settings.
Returns the database engine settings.
.PARAMETER Version
Specifies the version for which to return settings for.
.PARAMETER InstanceId
Specifies the instance id on which to check if component is installed.
.OUTPUTS
`[System.Management.Automation.PSCustomObject]`
.EXAMPLE
Get-SqlDscIntegrationServicesSetting -Version ([System.Version] '16.0')
Get-SqlDscDatabaseEngineSetting -InstanceId 'MSSQL13.SQL2016'
Returns the settings for the integration services.
Returns the settings for the database engine.
#>
function Get-SqlDscDatabaseEngineSetting
{
Expand All @@ -23,62 +23,36 @@ function Get-SqlDscDatabaseEngineSetting
param
(
[Parameter(Mandatory = $true)]
[System.Version]
$Version
[System.String]
$InstanceId
)

<#
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL13.SQL2016\Setup
FeatureList
Version
PatchLevel
Edition
EditionType
Language
ProductCode
SqlPath
TODO: Gör en Get-SqlDscServiceName med data från HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Services
Liknande Get-SqlDscInstalledInstance
#>
$masterDataServicesSettings = $null
$databaseEngineSettings = $null

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

$mdsCoreFeatureSettings = Get-ItemProperty @getItemPropertyParameters
$setupSettings = Get-ItemProperty @getItemPropertyParameters

if (-not $mdsCoreFeatureSettings)
if (-not $setupSettings)
{
$missingIntegrationServiceMessage = $script:localizedData.MasterDataServicesSetting_Get_NotInstalled -f $Version.ToString()
$missingDatabaseEngineMessage = $script:localizedData.DatabaseEngineSetting_Get_NotInstalled -f $Version.ToString()

$writeErrorParameters = @{
Message = $missingIntegrationServiceMessage
Category = 'InvalidOperation'
ErrorId = 'GISS0001' # cspell: disable-line
Message = $missingDatabaseEngineMessage
Category = 'InvalidOperation'
ErrorId = 'GISS0001' # cspell: disable-line
TargetObject = $Version
}

Write-Error @writeErrorParameters
}
else
{
$masterDataServicesSettings1 = [InstalledComponentSetting]::Parse($mdsCoreFeatureSettings)

$getItemPropertyParameters = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{0}0\Master Data Services\Setup' -f $Version.Major
ErrorAction = 'SilentlyContinue'
}

$mdsSetupSettings = Get-ItemProperty @getItemPropertyParameters

$masterDataServicesSettings2 = [InstalledComponentSetting]::Parse($mdsSetupSettings)

$masterDataServicesSettings = $masterDataServicesSettings1 + $masterDataServicesSettings2
$databaseEngineSettings = [InstalledComponentSetting]::Parse($setupSettings)
}

return $masterDataServicesSettings
return $databaseEngineSettings
}
38 changes: 21 additions & 17 deletions source/Public/Get-SqlDscInstalledComponent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ function Get-SqlDscInstalledComponent

switch ($currentServiceComponent.ServiceType)
{
# TODO: Add a Test-command for the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL13.SQL2016\ConfigurationState\SQL_Engine_Core_Inst
'DatabaseEngine'
{
$installedComponent.Feature = 'SQLEngine'

break
}

# TODO: Add a Test-command for the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL16.SQL2022\ConfigurationState\SQL_FullText_Adv
'9'
{
Expand Down Expand Up @@ -114,7 +106,7 @@ function Get-SqlDscInstalledComponent
Add-Member -MemberType 'NoteProperty' -Name 'InstanceId' -Value (
$currentServiceComponent.ServiceType |
Get-InstanceId -InstanceName $currentServiceComponent.InstanceName
)
)
}

$installedComponents += $installedComponent
Expand Down Expand Up @@ -232,16 +224,28 @@ function Get-SqlDscInstalledComponent

foreach ($currentInstance in $installedDatabaseEngineInstance)
{
# Look for installed version of Database Engine.
$databaseEngineSettings = Get-SqlDscDatabaseEngineSetting -InstanceId $currentInstance.InstanceId -ErrorAction 'SilentlyContinue'

if ($databaseEngineSettings)
{
$installedComponents += [PSCustomObject] @{
Feature = 'SQLENGINE'
InstanceName = $currentInstance.InstanceName
Version = $databaseEngineSettings.Version
}
}

# Looking for installed version for Replication.
$isReplicationInstalled = Test-SqlDscIsReplicationInstalled -InstanceId $currentInstance.InstanceId

if ($isReplicationInstalled)
{
$installedComponents += [PSCustomObject] @{
Feature = 'Replication'
Feature = 'Replication'
#Version = $currentInstance.Version
InstanceName = $currentInstance.InstanceName
InstanceId = $currentInstance.InstanceId
InstanceId = $currentInstance.InstanceId
}
}

Expand All @@ -251,10 +255,10 @@ function Get-SqlDscInstalledComponent
if ($isReplicationInstalled)
{
$installedComponents += [PSCustomObject] @{
Feature = 'AdvancedAnalytics'
Feature = 'AdvancedAnalytics'
#Version = $currentInstance.Version
InstanceName = $currentInstance.InstanceName
InstanceId = $currentInstance.InstanceId
InstanceId = $currentInstance.InstanceId
}
}

Expand All @@ -263,10 +267,10 @@ function Get-SqlDscInstalledComponent
if ($isDataQualityServerInstalled)
{
$installedComponents += [PSCustomObject] @{
Feature = 'DQ'
Feature = 'DQ'
#Version = $currentInstance.Version
InstanceName = $currentInstance.InstanceName
InstanceId = $currentInstance.InstanceId
InstanceId = $currentInstance.InstanceId
}
}

Expand All @@ -275,10 +279,10 @@ function Get-SqlDscInstalledComponent
if ($isROpenRPackagesInstalled)
{
$installedComponents += [PSCustomObject] @{
Feature = 'SQL_INST_MR'
Feature = 'SQL_INST_MR'
#Version = $currentInstance.Version
InstanceName = $currentInstance.InstanceName
InstanceId = $currentInstance.InstanceId
InstanceId = $currentInstance.InstanceId
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/Public/Get-SqlDscMasterDataServicesSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ function Get-SqlDscMasterDataServicesSetting

if (-not $mdsCoreFeatureSettings)
{
$missingIntegrationServiceMessage = $script:localizedData.MasterDataServicesSetting_Get_NotInstalled -f $Version.ToString()
$missingMasterDataServicesMessage = $script:localizedData.MasterDataServicesSetting_Get_NotInstalled -f $Version.ToString()

$writeErrorParameters = @{
Message = $missingIntegrationServiceMessage
Message = $missingMasterDataServicesMessage
Category = 'InvalidOperation'
ErrorId = 'GISS0001' # cspell: disable-line
TargetObject = $Version
Expand Down
54 changes: 54 additions & 0 deletions source/Public/Get-SqlDscServiceType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<#
.SYNOPSIS
Returns all the registered service types.
.DESCRIPTION
Returns all the registered service types.
.OUTPUTS
`[System.Object[]]`
.EXAMPLE
Get-SqlDscServiceType
Returns all service types.
#>
function Get-SqlDscServiceType
{
[CmdletBinding()]
[OutputType([System.Object[]])]
param ()

$registeredServiceTypes = @()

$registeredServiceType = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Services'

foreach ($currentServiceType in $registeredServiceType)
{
$foundServiceType = [PSCustomObject]@{
DisplayName = $currentServiceType.PSChildName
}

$properties = $currentServiceType.GetValueNames()

foreach ($property in $properties)
{
$foundServiceType |
Add-Member -MemberType 'NoteProperty' -Name $property -Value $currentServiceType.GetValue($property)
}

$managedServiceType = [Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]::Parse([Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType], $currentServiceType.GetValue('Type'))

$foundServiceType |
Add-Member -MemberType 'NoteProperty' -Name 'ManagedServiceType' -Value $managedServiceType

$foundServiceType |
Add-Member -MemberType 'NoteProperty' -Name 'NormalizedServiceType' -Value (
ConvertFrom-ManagedServiceType -ServiceType $managedServiceType -ErrorAction 'SilentlyContinue'
)

$registeredServiceTypes += $foundServiceType
}

return $registeredServiceTypes
}
3 changes: 3 additions & 0 deletions source/en-US/SqlServerDsc.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,7 @@ ConvertFrom-StringData @'
## Get-SqlDscMasterDataServicesSetting
MasterDataServicesSetting_Get_NotInstalled = There are no Master Data Services installed with version {0}.
## Get-SqlDscDatabaseEngineSetting
DatabaseEngineSetting_Get_NotInstalled = There are no Database Engine installed with version {0}.
'@

0 comments on commit e0af130

Please sign in to comment.