Skip to content

Commit

Permalink
Modify and add commands
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Jun 18, 2023
1 parent e7003a9 commit be3c785
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 74 deletions.
61 changes: 61 additions & 0 deletions source/Public/Get-SqlDscDatabaseEngineInstalledSetting.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<#
.SYNOPSIS
Returns the database engine settings.
.DESCRIPTION
Returns the database engine settings.
.PARAMETER InstanceId
Specifies the instance id on which to check if component is installed.
.OUTPUTS
`[System.Management.Automation.PSCustomObject]`
.EXAMPLE
Get-SqlDscDatabaseEngineInstalledSetting -InstanceId 'MSSQL13.SQL2016'
Returns the settings for the database engine.
#>
function Get-SqlDscDatabaseEngineInstalledSetting
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.String]
$InstanceId
)

process
{
$databaseEngineSettings = $null

$getItemPropertyParameters = @{
Path = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{0}\Setup' -f $InstanceId
ErrorAction = 'SilentlyContinue'
}

$setupSettings = Get-ItemProperty @getItemPropertyParameters

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

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

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

return $databaseEngineSettings
}
}
58 changes: 0 additions & 58 deletions source/Public/Get-SqlDscDatabaseEngineSetting.ps1

This file was deleted.

12 changes: 6 additions & 6 deletions source/Public/Get-SqlDscInstalledComponent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ function Get-SqlDscInstalledComponent
{
$databaseLevelVersion = [System.Version] ('{0}.{1}' -f $databaseLevel.Substring(0, 2), $databaseLevel.Substring(2, 1))

$integrationServicesSettings = Get-SqlDscIntegrationServicesSetting -Version $databaseLevelVersion -ErrorAction 'SilentlyContinue'
$isIntegrationServicesInstalled = Test-SqlDscIsIntegrationServicesInstalled -Version $databaseLevelVersion

if ($integrationServicesSettings)
if ($isIntegrationServicesInstalled)
{
$installedComponents += [PSCustomObject] @{
Feature = 'IS'
Version = $integrationServicesSettings.Version
Version = $databaseLevelVersion
}
}

Expand Down Expand Up @@ -186,13 +186,13 @@ function Get-SqlDscInstalledComponent
}

# Look for installed version of Master Data Services.
$masterDataServicesSettings = Get-SqlDscMasterDataServicesSetting -Version $databaseLevelVersion -ErrorAction 'SilentlyContinue'
$masterDataServicesSettings = Test-SqlDscIsMasterDataServicesInstalled -Version $databaseLevelVersion

if ($masterDataServicesSettings)
{
$installedComponents += [PSCustomObject] @{
Feature = 'MDS'
Version = $masterDataServicesSettings.Version
Version = $databaseLevelVersion
}
}

Expand Down Expand Up @@ -225,7 +225,7 @@ function Get-SqlDscInstalledComponent
foreach ($currentInstance in $installedDatabaseEngineInstance)
{
# Look for installed version of Database Engine.
$databaseEngineSettings = Get-SqlDscDatabaseEngineSetting -InstanceId $currentInstance.InstanceId -ErrorAction 'SilentlyContinue'
$databaseEngineSettings = Get-SqlDscDatabaseEngineInstalledSetting -InstanceId $currentInstance.InstanceId -ErrorAction 'SilentlyContinue'

if ($databaseEngineSettings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
`[System.Management.Automation.PSCustomObject]`
.EXAMPLE
Get-SqlDscIntegrationServicesSetting -Version ([System.Version] '16.0')
Get-SqlDscIntegrationServicesInstalledSetting -Version ([System.Version] '16.0')
Returns the settings for the Integration Services.
#>
function Get-SqlDscIntegrationServicesSetting
function Get-SqlDscIntegrationServicesInstalledSetting
{
[CmdletBinding()]
[OutputType([System.Boolean])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
`[System.Management.Automation.PSCustomObject]`
.EXAMPLE
Get-SqlDscIntegrationServicesSetting -Version ([System.Version] '16.0')
Get-SqlDscMasterDataServicesInstalledSetting -Version ([System.Version] '16.0')
Returns the settings for the integration services.
#>
function Get-SqlDscMasterDataServicesSetting
function Get-SqlDscMasterDataServicesInstalledSetting
{
[CmdletBinding()]
[OutputType([System.Boolean])]
Expand Down
84 changes: 84 additions & 0 deletions source/Public/Test-SqlDscIsDatabaseEngineInstalled.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<#
.SYNOPSIS
Returns whether the Master Data Services are installed.
.DESCRIPTION
Returns whether the Master Data Services are installed.
.PARAMETER Version
Specifies the version for which to check if component is installed.
.PARAMETER InstanceName
Specifies the instance name on which to check if component is installed.
.PARAMETER InstanceId
Specifies the instance id on which to check if component is installed.
.OUTPUTS
[System.Boolean]
.EXAMPLE
Test-SqlDscIsDatabaseEngineInstalled -Version ([System.Version] '16.0')
Returns $true if Database Engine with version 16 is installed.
.NOTES
The parameters are all mutually exclusive.
#>
function Test-SqlDscIsDatabaseEngineInstalled
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter()]
[System.Version]
$Version,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$InstanceName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$InstanceId
)

$commandParameter = (Remove-CommonParameter -Hashtable $PSCmdlet.MyInvocation.MyCommand.Parameters).Keys

foreach ($currentParameterName in $commandParameter)
{
$assertBoundParameterParameters = @{
BoundParameterList = $PSBoundParameters
MutuallyExclusiveList1 = $currentParameterName
MutuallyExclusiveList2 = @([System.String[]] $commandParameter.Where({ $_ -ne $currentParameterName }))
}

Assert-BoundParameter @assertBoundParameterParameters
}

$getSqlDscInstalledInstanceParameters = @{
ServiceType = 'DatabaseEngine'
}

$installedInstances = Get-SqlDscInstalledInstance @getSqlDscInstalledInstanceParameters -ErrorAction 'SilentlyContinue'

$result = $false

if ($PSBoundParameters.ContainsKey('InstanceId'))
{
$result = $installedInstances.InstanceId -contains $InstanceId
}
elseif ($PSBoundParameters.ContainsKey('InstanceName'))
{
$result = $installedInstances.InstanceName -contains $InstanceName
}
elseif ($PSBoundParameters.ContainsKey('Version'))
{
$result = ($installedInstances.InstanceId | Get-SqlDscDatabaseEngineInstalledSetting).Version.Major -contains $Version.Major
}

return $result
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Test-SqlDscIsIntegrationServicesInstalled

$result = $false

if ((Get-SqlDscIntegrationServicesSetting -Version $Version -ErrorAction 'SilentlyContinue'))
if ((Get-SqlDscIntegrationServicesInstalledSetting -Version $Version -ErrorAction 'SilentlyContinue'))
{
$result = $true
}
Expand Down
4 changes: 2 additions & 2 deletions source/Public/Test-SqlDscIsMasterDataServicesInstalled.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[System.Boolean]
.EXAMPLE
IsMasterDataServicesInstalled -Version ([System.Version] '16.0')
Test-SqlDscIsMasterDataServicesInstalled -Version ([System.Version] '16.0')
Returns $true if Master Data Services are installed.
#>
Expand All @@ -29,7 +29,7 @@ function Test-SqlDscIsMasterDataServicesInstalled

$result = $false

if ((Get-SqlDscMasterDataServicesSetting -Version $Version -ErrorAction 'SilentlyContinue'))
if ((Get-SqlDscMasterDataServicesInstalledSetting -Version $Version -ErrorAction 'SilentlyContinue'))
{
$result = $true
}
Expand Down
6 changes: 3 additions & 3 deletions source/en-US/SqlServerDsc.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ ConvertFrom-StringData @'
## Test-IsManagementStudioAdvancedInstalled
IsManagementStudioAdvancedInstalled_Test_NotSupportedVersion = SQL Server Management Studio Advanced is not supported for the provided version.
## Get-SqlDscIntegrationServicesSetting
## Get-SqlDscIntegrationServicesInstalledSetting
IntegrationServicesSetting_Get_NotInstalled = There are no Integration Services installed with version {0}.
## Get-SqlDscMasterDataServicesSetting
## Get-SqlDscMasterDataServicesInstalledSetting
MasterDataServicesSetting_Get_NotInstalled = There are no Master Data Services installed with version {0}.
## Get-SqlDscDatabaseEngineSetting
## Get-SqlDscDatabaseEngineInstalledSetting
DatabaseEngineSetting_Get_NotInstalled = There are no Database Engine installed with version {0}.
'@

0 comments on commit be3c785

Please sign in to comment.