-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
161 additions
and
74 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
source/Public/Get-SqlDscDatabaseEngineInstalledSetting.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters