Skip to content

Commit 8fe15c9

Browse files
committed
Add Test-SqlDscIsInstalledComponent function to check SQL Server component installations
1 parent 0430533 commit 8fe15c9

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<#
2+
.SYNOPSIS
3+
Tests whether a specific SQL Server component is installed.
4+
5+
.DESCRIPTION
6+
Tests whether a specific SQL Server component is installed on the system.
7+
This command provides a generic way to check for component installations
8+
by specifying the component type. This command replaces the individual
9+
component-specific test commands (Test-SqlDscIsBackwardCompatibilityComponentsInstalled,
10+
Test-SqlDscIsBooksOnlineInstalled, etc.) by consolidating their logic into
11+
a single, flexible command.
12+
13+
.PARAMETER Component
14+
Specifies one or more SQL Server components to check for installation.
15+
16+
.PARAMETER Version
17+
Specifies the version for which to check if the component is installed.
18+
Optional for version-based components.
19+
20+
.PARAMETER InstanceId
21+
Specifies the instance ID for which to check if the component is installed.
22+
Required for instance-based components: DataQualityServer, Replication,
23+
ROpenRPackages, and RServices.
24+
25+
.OUTPUTS
26+
[System.Boolean]
27+
28+
Returns $true if the specified component is installed, $false otherwise.
29+
30+
.EXAMPLE
31+
Test-SqlDscIsInstalledComponent -Component IntegrationServices -Version ([System.Version] '16.0')
32+
33+
Returns $true if Integration Services version 16.0 are installed.
34+
35+
.EXAMPLE
36+
Test-SqlDscIsInstalledComponent -Component IntegrationServices
37+
38+
Returns $true if any version of Integration Services is installed.
39+
40+
.EXAMPLE
41+
Test-SqlDscIsInstalledComponent -Component IntegrationServices, ManagementStudio
42+
43+
Returns $true if any version of Integration Services or Management Studio is installed.
44+
45+
.EXAMPLE
46+
Test-SqlDscIsInstalledComponent -Component Replication -InstanceId 'MSSQL16.SQL2022'
47+
48+
Returns $true if Replication is installed for the specified instance.
49+
50+
.EXAMPLE
51+
Test-SqlDscIsInstalledComponent -Component BooksOnline -Version ([System.Version] '15.0')
52+
53+
Returns $true if SQL Server Books Online version 15.0 is installed.
54+
55+
.EXAMPLE
56+
Test-SqlDscIsInstalledComponent -Component ManagementStudio -Version ([System.Version] '12.0')
57+
58+
Returns $true if SQL Server Management Studio 2014 (version 12.0) is installed.
59+
#>
60+
function Test-SqlDscIsInstalledComponent
61+
{
62+
[CmdletBinding(DefaultParameterSetName = 'ByComponent')]
63+
[OutputType([System.Boolean])]
64+
param
65+
(
66+
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
67+
[SqlServerComponent[]]
68+
$Component,
69+
70+
[Parameter(ParameterSetName = 'ByComponent')]
71+
[Parameter(ParameterSetName = 'ByVersion')]
72+
[System.Version]
73+
$Version,
74+
75+
[Parameter(Mandatory = $true, ParameterSetName = 'ByInstanceId')]
76+
[System.String]
77+
$InstanceId
78+
)
79+
80+
$getInstalledComponentParameters = @{
81+
Component = $Component
82+
}
83+
84+
if ($Version)
85+
{
86+
$getInstalledComponentParameters['Version'] = $Version
87+
}
88+
89+
if ($InstanceId)
90+
{
91+
$getInstalledComponentParameters['InstanceId'] = $InstanceId
92+
}
93+
94+
$installedComponents = Get-SqlDscInstalledComponent @getInstalledComponentParameters
95+
96+
return ($installedComponents.Count -gt 0)
97+
}

0 commit comments

Comments
 (0)