From 889524bd4eda7e0e807d5fe89ca4b61cbe865cb0 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 1 May 2023 09:28:22 +0200 Subject: [PATCH] Iteration 3 --- .../Get-SqlDscDatabaseEngineSetting.ps1 | 62 ++++++------------- .../Public/Get-SqlDscInstalledComponent.ps1 | 38 +++++++----- .../Get-SqlDscMasterDataServicesSetting.ps1 | 4 +- source/Public/Get-SqlDscServiceType.ps1 | 54 ++++++++++++++++ source/en-US/SqlServerDsc.strings.psd1 | 3 + 5 files changed, 98 insertions(+), 63 deletions(-) create mode 100644 source/Public/Get-SqlDscServiceType.ps1 diff --git a/source/Public/Get-SqlDscDatabaseEngineSetting.ps1 b/source/Public/Get-SqlDscDatabaseEngineSetting.ps1 index cdacea515..472734ca3 100644 --- a/source/Public/Get-SqlDscDatabaseEngineSetting.ps1 +++ b/source/Public/Get-SqlDscDatabaseEngineSetting.ps1 @@ -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 { @@ -23,42 +23,27 @@ 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 } @@ -66,19 +51,8 @@ function Get-SqlDscDatabaseEngineSetting } 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 } diff --git a/source/Public/Get-SqlDscInstalledComponent.ps1 b/source/Public/Get-SqlDscInstalledComponent.ps1 index 4ca6c65a0..85403aa2b 100644 --- a/source/Public/Get-SqlDscInstalledComponent.ps1 +++ b/source/Public/Get-SqlDscInstalledComponent.ps1 @@ -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' { @@ -114,7 +106,7 @@ function Get-SqlDscInstalledComponent Add-Member -MemberType 'NoteProperty' -Name 'InstanceId' -Value ( $currentServiceComponent.ServiceType | Get-InstanceId -InstanceName $currentServiceComponent.InstanceName - ) + ) } $installedComponents += $installedComponent @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } } diff --git a/source/Public/Get-SqlDscMasterDataServicesSetting.ps1 b/source/Public/Get-SqlDscMasterDataServicesSetting.ps1 index 93a4bab9b..3d72f632d 100644 --- a/source/Public/Get-SqlDscMasterDataServicesSetting.ps1 +++ b/source/Public/Get-SqlDscMasterDataServicesSetting.ps1 @@ -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 diff --git a/source/Public/Get-SqlDscServiceType.ps1 b/source/Public/Get-SqlDscServiceType.ps1 new file mode 100644 index 000000000..8eadcdd0a --- /dev/null +++ b/source/Public/Get-SqlDscServiceType.ps1 @@ -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 +} diff --git a/source/en-US/SqlServerDsc.strings.psd1 b/source/en-US/SqlServerDsc.strings.psd1 index 470a91bff..620f7e318 100644 --- a/source/en-US/SqlServerDsc.strings.psd1 +++ b/source/en-US/SqlServerDsc.strings.psd1 @@ -194,4 +194,7 @@ PreferredModule_ModuleVersionNotFound = No preferred Powershell module with vers ## 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}. '@