|
| 1 | +<# |
| 2 | + .SYNOPSIS |
| 3 | + Returns whether the Master Data Services are installed. |
| 4 | +
|
| 5 | + .DESCRIPTION |
| 6 | + Returns whether the Master Data Services are installed. |
| 7 | +
|
| 8 | + .PARAMETER Version |
| 9 | + Specifies the version for which to check if component is installed. |
| 10 | +
|
| 11 | + .PARAMETER InstanceName |
| 12 | + Specifies the instance name on which to check if component is installed. |
| 13 | +
|
| 14 | + .PARAMETER InstanceId |
| 15 | + Specifies the instance id on which to check if component is installed. |
| 16 | +
|
| 17 | + .OUTPUTS |
| 18 | + [System.Boolean] |
| 19 | +
|
| 20 | + .EXAMPLE |
| 21 | + Test-SqlDscIsDatabaseEngineInstalled -Version ([System.Version] '16.0') |
| 22 | +
|
| 23 | + Returns $true if Database Engine with version 16 is installed. |
| 24 | +
|
| 25 | + .NOTES |
| 26 | + The parameters are all mutually exclusive. |
| 27 | +#> |
| 28 | +function Test-SqlDscIsDatabaseEngineInstalled |
| 29 | +{ |
| 30 | + [CmdletBinding()] |
| 31 | + [OutputType([System.Boolean])] |
| 32 | + param |
| 33 | + ( |
| 34 | + [Parameter()] |
| 35 | + [System.Version] |
| 36 | + $Version, |
| 37 | + |
| 38 | + [Parameter()] |
| 39 | + [ValidateNotNullOrEmpty()] |
| 40 | + [System.String] |
| 41 | + $InstanceName, |
| 42 | + |
| 43 | + [Parameter()] |
| 44 | + [ValidateNotNullOrEmpty()] |
| 45 | + [System.String] |
| 46 | + $InstanceId |
| 47 | + ) |
| 48 | + |
| 49 | + $commandParameter = (Remove-CommonParameter -Hashtable $PSCmdlet.MyInvocation.MyCommand.Parameters).Keys |
| 50 | + |
| 51 | + foreach ($currentParameterName in $commandParameter) |
| 52 | + { |
| 53 | + $assertBoundParameterParameters = @{ |
| 54 | + BoundParameterList = $PSBoundParameters |
| 55 | + MutuallyExclusiveList1 = $currentParameterName |
| 56 | + MutuallyExclusiveList2 = @([System.String[]] $commandParameter.Where({ $_ -ne $currentParameterName })) |
| 57 | + } |
| 58 | + |
| 59 | + Assert-BoundParameter @assertBoundParameterParameters |
| 60 | + } |
| 61 | + |
| 62 | + $getSqlDscInstalledInstanceParameters = @{ |
| 63 | + ServiceType = 'DatabaseEngine' |
| 64 | + } |
| 65 | + |
| 66 | + $installedInstances = Get-SqlDscInstalledInstance @getSqlDscInstalledInstanceParameters -ErrorAction 'SilentlyContinue' |
| 67 | + |
| 68 | + $result = $false |
| 69 | + |
| 70 | + if ($PSBoundParameters.ContainsKey('InstanceId')) |
| 71 | + { |
| 72 | + $result = $installedInstances.InstanceId -contains $InstanceId |
| 73 | + } |
| 74 | + elseif ($PSBoundParameters.ContainsKey('InstanceName')) |
| 75 | + { |
| 76 | + $result = $installedInstances.InstanceName -contains $InstanceName |
| 77 | + } |
| 78 | + elseif ($PSBoundParameters.ContainsKey('Version')) |
| 79 | + { |
| 80 | + $result = ($installedInstances.InstanceId | Get-SqlDscDatabaseEngineInstalledSetting).Version.Major -contains $Version.Major |
| 81 | + } |
| 82 | + |
| 83 | + return $result |
| 84 | +} |
0 commit comments