Skip to content

Commit b0e7941

Browse files
committed
Get-SqlDscRSPackage: Retrieving SSRS and PBIRS package information
1 parent a45049f commit b0e7941

File tree

8 files changed

+637
-1
lines changed

8 files changed

+637
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Added
99

10+
- Added public command `Get-SqlDscRSPackage` to retrieve package information for
11+
SQL Server Reporting Services or Power BI Report Server. Supports getting version
12+
information from an installed package or from an executable file
13+
([issue #2082](https://github.com/dsccommunity/SqlServerDsc/issues/2082)).
1014
- Added public command `Get-SqlDscBackupFileList` to read the list of database
1115
files contained in a SQL Server backup file. Useful for planning file
1216
relocations during restore operations ([issue #2026](https://github.com/dsccommunity/SqlServerDsc/issues/2026)).

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ stages:
531531
'tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1'
532532
# Group 2
533533
'tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1'
534+
'tests/Integration/Commands/Get-SqlDscRSPackage.Integration.Tests.ps1'
534535
'tests/Integration/Commands/Get-SqlDscRSSetupConfiguration.Integration.Tests.ps1'
535536
'tests/Integration/Commands/Test-SqlDscRSInstalled.Integration.Tests.ps1'
536537
# Group 8
@@ -596,6 +597,7 @@ stages:
596597
'tests/Integration/Commands/Install-SqlDscPowerBIReportServer.Integration.Tests.ps1'
597598
# Group 2
598599
'tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1'
600+
'tests/Integration/Commands/Get-SqlDscRSPackage.Integration.Tests.ps1'
599601
'tests/Integration/Commands/Get-SqlDscRSSetupConfiguration.Integration.Tests.ps1'
600602
'tests/Integration/Commands/Test-SqlDscRSInstalled.Integration.Tests.ps1'
601603
# Group 8
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<#
2+
.SYNOPSIS
3+
Gets package information for SQL Server Reporting Services or Power BI
4+
Report Server.
5+
6+
.DESCRIPTION
7+
Gets package information for an installed SQL Server Reporting Services or
8+
Power BI Report Server package, or from a setup executable file. The command
9+
returns file version information including product name, product version,
10+
file version, and other version-related metadata.
11+
12+
When using the `Package` parameter, the command retrieves the installed
13+
package executable and returns its version information.
14+
15+
When using the `FilePath` parameter, the command returns version information
16+
from the specified executable file.
17+
18+
.PARAMETER Package
19+
Specifies if either the Reporting Services or Power BI Report Server package
20+
should be retrieved. Valid values are 'SSRS' and 'PBIRS'.
21+
22+
.PARAMETER FilePath
23+
Specifies the path to the executable file to return version information for.
24+
The file must have a product name matching either 'Microsoft SQL Server
25+
Reporting Services' or 'Microsoft Power BI Report Server'.
26+
27+
.PARAMETER Force
28+
If specified, the ProductName validation is skipped when using the FilePath
29+
parameter. This allows retrieving version information for executables with
30+
different product names.
31+
32+
.EXAMPLE
33+
Get-SqlDscRSPackage -Package 'SSRS'
34+
35+
Returns package information for the installed SQL Server Reporting Services
36+
package.
37+
38+
.EXAMPLE
39+
Get-SqlDscRSPackage -Package 'PBIRS'
40+
41+
Returns package information for the installed Power BI Report Server package.
42+
43+
.EXAMPLE
44+
Get-SqlDscRSPackage -FilePath 'E:\SQLServerReportingServices.exe'
45+
46+
Returns package information from the specified SQL Server Reporting Services
47+
executable file.
48+
49+
.EXAMPLE
50+
Get-SqlDscRSPackage -FilePath 'E:\PBIReportServer.exe'
51+
52+
Returns package information from the specified Power BI Report Server
53+
executable file.
54+
55+
.EXAMPLE
56+
Get-SqlDscRSPackage -FilePath 'E:\CustomReportServer.exe' -Force
57+
58+
Returns package information from the specified executable file without
59+
validating the product name.
60+
61+
.INPUTS
62+
None.
63+
64+
.OUTPUTS
65+
`System.Diagnostics.FileVersionInfo`
66+
67+
Returns the file version information for the package.
68+
#>
69+
function Get-SqlDscRSPackage
70+
{
71+
# cSpell: ignore PBIRS
72+
[CmdletBinding(DefaultParameterSetName = 'Package')]
73+
[OutputType([System.Diagnostics.FileVersionInfo])]
74+
param
75+
(
76+
[Parameter(Mandatory = $true, ParameterSetName = 'Package')]
77+
[ValidateSet('SSRS', 'PBIRS')]
78+
[System.String]
79+
$Package,
80+
81+
[Parameter(Mandatory = $true, ParameterSetName = 'FilePath')]
82+
[System.String]
83+
$FilePath,
84+
85+
[Parameter(ParameterSetName = 'FilePath')]
86+
[System.Management.Automation.SwitchParameter]
87+
$Force
88+
)
89+
90+
$versionInfo = $null
91+
$validProductNames = @(
92+
'Microsoft SQL Server Reporting Services'
93+
'Microsoft Power BI Report Server'
94+
)
95+
96+
if ($PSCmdlet.ParameterSetName -eq 'Package')
97+
{
98+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_GettingInstalledPackage -f $Package)
99+
100+
$rsSetupConfiguration = Get-SqlDscRSSetupConfiguration -InstanceName $Package -ErrorAction 'SilentlyContinue'
101+
102+
if (-not $rsSetupConfiguration)
103+
{
104+
$errorMessage = $script:localizedData.Get_SqlDscRSPackage_PackageNotFound -f $Package
105+
106+
$PSCmdlet.ThrowTerminatingError(
107+
[System.Management.Automation.ErrorRecord]::new(
108+
[System.InvalidOperationException]::new($errorMessage),
109+
'GSDRSP0001',
110+
[System.Management.Automation.ErrorCategory]::ObjectNotFound,
111+
$Package
112+
)
113+
)
114+
}
115+
116+
$installFolder = $rsSetupConfiguration.InstallFolder
117+
118+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_FoundInstallFolder -f $installFolder)
119+
120+
# Determine the executable name based on package type
121+
if ($Package -eq 'SSRS')
122+
{
123+
$executablePath = Join-Path -Path $installFolder -ChildPath 'RSHostingService\ReportingServicesService.exe'
124+
}
125+
else
126+
{
127+
# PBIRS
128+
$executablePath = Join-Path -Path $installFolder -ChildPath 'RSHostingService\ReportingServicesService.exe'
129+
}
130+
131+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_GettingVersionInfo -f $executablePath)
132+
133+
$versionInfo = Get-FileVersion -Path $executablePath
134+
}
135+
else
136+
{
137+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_GettingVersionFromFile -f $FilePath)
138+
139+
$versionInfo = Get-FileVersion -Path $FilePath
140+
141+
if (-not $Force.IsPresent)
142+
{
143+
if ($versionInfo.ProductName -notin $validProductNames)
144+
{
145+
$errorMessage = $script:localizedData.Get_SqlDscRSPackage_InvalidProductName -f $versionInfo.ProductName, ($validProductNames -join "', '")
146+
147+
$PSCmdlet.ThrowTerminatingError(
148+
[System.Management.Automation.ErrorRecord]::new(
149+
[System.InvalidOperationException]::new($errorMessage),
150+
'GSDRSP0002',
151+
[System.Management.Automation.ErrorCategory]::InvalidArgument,
152+
$FilePath
153+
)
154+
)
155+
}
156+
}
157+
}
158+
159+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_ReturningVersionInfo -f $versionInfo.ProductName, $versionInfo.ProductVersion)
160+
161+
return $versionInfo
162+
}

source/en-US/SqlServerDsc.strings.psd1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,4 +662,13 @@ ConvertFrom-StringData @'
662662
## Get-SqlDscDateTime
663663
Get_SqlDscDateTime_RetrievingDateTime = Retrieving date and time using {0}(). (GSDD0001)
664664
Get_SqlDscDateTime_FailedToRetrieve = Failed to retrieve date and time using {0}(): {1} (GSDD0002)
665+
666+
## Get-SqlDscRSPackage
667+
Get_SqlDscRSPackage_GettingInstalledPackage = Getting installed package information for '{0}'. (GSDRSP0003)
668+
Get_SqlDscRSPackage_PackageNotFound = The package '{0}' was not found. Ensure that the package is installed. (GSDRSP0001)
669+
Get_SqlDscRSPackage_FoundInstallFolder = Found install folder '{0}'. (GSDRSP0004)
670+
Get_SqlDscRSPackage_GettingVersionInfo = Getting version information from '{0}'. (GSDRSP0005)
671+
Get_SqlDscRSPackage_GettingVersionFromFile = Getting version information from file '{0}'. (GSDRSP0006)
672+
Get_SqlDscRSPackage_InvalidProductName = The product name '{0}' is not a valid Reporting Services package. Expected product names are: '{1}'. Use the Force parameter to skip this validation. (GSDRSP0002)
673+
Get_SqlDscRSPackage_ReturningVersionInfo = Returning version information for '{0}' version '{1}'. (GSDRSP0007)
665674
'@
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
2+
param ()
3+
4+
BeforeDiscovery {
5+
try
6+
{
7+
if (-not (Get-Module -Name 'DscResource.Test'))
8+
{
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
10+
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
11+
{
12+
# Redirect all streams to $null, except the error stream (stream 2)
13+
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
14+
}
15+
16+
# If the dependencies have not been resolved, this will throw an error.
17+
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
18+
}
19+
}
20+
catch [System.IO.FileNotFoundException]
21+
{
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
23+
}
24+
}
25+
26+
BeforeAll {
27+
$script:moduleName = 'SqlServerDsc'
28+
29+
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
30+
}
31+
32+
Describe 'Get-SqlDscRSPackage' {
33+
Context 'When getting package information for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
34+
It 'Should return the package information for SSRS' {
35+
$result = Get-SqlDscRSPackage -Package 'SSRS' -ErrorAction 'Stop'
36+
37+
$result | Should -Not -BeNullOrEmpty
38+
$result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services'
39+
$result.FileVersion | Should -Not -BeNullOrEmpty
40+
$result.ProductVersion | Should -Not -BeNullOrEmpty
41+
}
42+
43+
It 'Should return the same result when using FilePath parameter' {
44+
# Get the install folder from the setup configuration
45+
$setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
46+
47+
$executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe'
48+
49+
$result = Get-SqlDscRSPackage -FilePath $executablePath -ErrorAction 'Stop'
50+
51+
$result | Should -Not -BeNullOrEmpty
52+
$result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services'
53+
$result.FileVersion | Should -Not -BeNullOrEmpty
54+
$result.ProductVersion | Should -Not -BeNullOrEmpty
55+
}
56+
}
57+
58+
Context 'When getting package information for Power BI Report Server' -Tag @('Integration_PowerBI') {
59+
# cSpell: ignore PBIRS
60+
It 'Should return the package information for PBIRS' {
61+
$result = Get-SqlDscRSPackage -Package 'PBIRS' -ErrorAction 'Stop'
62+
63+
$result | Should -Not -BeNullOrEmpty
64+
$result.ProductName | Should -Be 'Microsoft Power BI Report Server'
65+
$result.FileVersion | Should -Not -BeNullOrEmpty
66+
$result.ProductVersion | Should -Not -BeNullOrEmpty
67+
}
68+
69+
It 'Should return the same result when using FilePath parameter' {
70+
# Get the install folder from the setup configuration
71+
$setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop'
72+
73+
$executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe'
74+
75+
$result = Get-SqlDscRSPackage -FilePath $executablePath -ErrorAction 'Stop'
76+
77+
$result | Should -Not -BeNullOrEmpty
78+
$result.ProductName | Should -Be 'Microsoft Power BI Report Server'
79+
$result.FileVersion | Should -Not -BeNullOrEmpty
80+
$result.ProductVersion | Should -Not -BeNullOrEmpty
81+
}
82+
}
83+
84+
Context 'When getting package information for a non-existing package' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') {
85+
It 'Should throw an error when the package is not installed' {
86+
# PBIRS is not installed in the SSRS CI environment and vice versa
87+
# We can test this by checking which one is installed
88+
$ssrsInstalled = Test-SqlDscRSInstalled -InstanceName 'SSRS'
89+
90+
if ($ssrsInstalled)
91+
{
92+
# SSRS is installed, so PBIRS should not be
93+
{ Get-SqlDscRSPackage -Package 'PBIRS' -ErrorAction 'Stop' } | Should -Throw
94+
}
95+
else
96+
{
97+
# PBIRS is installed, so SSRS should not be
98+
{ Get-SqlDscRSPackage -Package 'SSRS' -ErrorAction 'Stop' } | Should -Throw
99+
}
100+
}
101+
}
102+
103+
Context 'When using Force parameter to bypass validation' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
104+
It 'Should return file version information for any executable with Force parameter' {
105+
# Get the install folder from the setup configuration
106+
$setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
107+
108+
$executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe'
109+
110+
# Using Force should work and return the file version info
111+
$result = Get-SqlDscRSPackage -FilePath $executablePath -Force -ErrorAction 'Stop'
112+
113+
$result | Should -Not -BeNullOrEmpty
114+
$result.FileVersion | Should -Not -BeNullOrEmpty
115+
}
116+
}
117+
118+
Context 'When using Force parameter to bypass validation' -Tag @('Integration_PowerBI') {
119+
It 'Should return file version information for any executable with Force parameter' {
120+
# Get the install folder from the setup configuration
121+
$setupConfig = Get-SqlDscRSSetupConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop'
122+
123+
$executablePath = Join-Path -Path $setupConfig.InstallFolder -ChildPath 'RSHostingService/ReportingServicesService.exe'
124+
125+
# Using Force should work and return the file version info
126+
$result = Get-SqlDscRSPackage -FilePath $executablePath -Force -ErrorAction 'Stop'
127+
128+
$result | Should -Not -BeNullOrEmpty
129+
$result.FileVersion | Should -Not -BeNullOrEmpty
130+
}
131+
}
132+
}

tests/Integration/Commands/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
162162
Import-SqlDscPreferredModule | 0 | - | - | -
163163
Install-SqlDscReportingService | 1 | 0 (Prerequisites) | - | SSRS instance
164164
Get-SqlDscInstalledInstance | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
165+
Get-SqlDscRSPackage | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
165166
Get-SqlDscRSSetupConfiguration | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
166167
Test-SqlDscRSInstalled | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
167168
Repair-SqlDscReportingService | 8 | 1 (Install-SqlDscReportingService) | SSRS | -
@@ -180,6 +181,7 @@ Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
180181
Import-SqlDscPreferredModule | 0 | - | - | -
181182
Install-SqlDscPowerBIReportServer | 1 | 0 (Prerequisites) | - | PBIRS instance
182183
Get-SqlDscInstalledInstance | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
184+
Get-SqlDscRSPackage | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
183185
Get-SqlDscRSSetupConfiguration | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
184186
Test-SqlDscRSInstalled | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
185187
Repair-SqlDscPowerBIReportServer | 8 | 1 (Install-SqlDscPowerBIReportServer) | PBIRS | -

tests/QA/ScriptAnalyzer.Tests.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ BeforeDiscovery {
3939
(from Indented.ScriptAnalyzerRules) can properly parse parameters that uses SMO types,
4040
e.g. [Microsoft.SqlServer.Management.Smo.Server].
4141
#>
42-
Add-Type -Path "$PSScriptRoot/../Unit/Stubs/SMO.cs" -ReferencedAssemblies 'System.Data', 'System.Xml'
42+
if ($IsLinux -or $IsMacOS)
43+
{
44+
# .NET Core requires different assemblies than .NET Framework
45+
$referencedAssemblies = @(
46+
'System.Collections'
47+
'System.Collections.Specialized'
48+
'System.Data.Common'
49+
'System.Linq'
50+
'System.Net.Primitives'
51+
'netstandard'
52+
)
53+
}
54+
else
55+
{
56+
$referencedAssemblies = @(
57+
'System.Data'
58+
'System.Xml'
59+
)
60+
}
61+
62+
Add-Type -Path "$PSScriptRoot/../Unit/Stubs/SMO.cs" -ReferencedAssemblies $referencedAssemblies
4363

4464
$repositoryPath = Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '../..')
4565
$sourcePath = Join-Path -Path $repositoryPath -ChildPath 'source'

0 commit comments

Comments
 (0)