Skip to content

Commit fdc54b9

Browse files
authored
Get-SqlDscRSPackage: Retrieving SSRS and PBIRS package information (#2378)
1 parent f2da1a2 commit fdc54b9

File tree

8 files changed

+425
-1
lines changed

8 files changed

+425
-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 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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 a SQL Server Reporting Services or Power BI
8+
Report Server executable file. The command returns file version information
9+
including product name, product version, file version, and other
10+
version-related metadata.
11+
12+
.PARAMETER FilePath
13+
Specifies the path to the executable file to return version information for.
14+
The file must have a product name matching either 'Microsoft SQL Server
15+
Reporting Services' or 'Microsoft Power BI Report Server'.
16+
17+
.PARAMETER Force
18+
If specified, the ProductName validation is skipped. This allows retrieving
19+
version information for executables with different product names.
20+
21+
.EXAMPLE
22+
Get-SqlDscRSPackage -FilePath 'E:\SQLServerReportingServices.exe'
23+
24+
Returns package information from the specified SQL Server Reporting Services
25+
executable file.
26+
27+
.EXAMPLE
28+
Get-SqlDscRSPackage -FilePath 'E:\PBIReportServer.exe'
29+
30+
Returns package information from the specified Power BI Report Server
31+
executable file.
32+
33+
.EXAMPLE
34+
Get-SqlDscRSPackage -FilePath 'E:\CustomReportServer.exe' -Force
35+
36+
Returns package information from the specified executable file without
37+
validating the product name.
38+
39+
.INPUTS
40+
None.
41+
42+
.OUTPUTS
43+
`System.Diagnostics.FileVersionInfo`
44+
45+
Returns the file version information for the package.
46+
#>
47+
function Get-SqlDscRSPackage
48+
{
49+
# cSpell: ignore PBIRS
50+
[CmdletBinding()]
51+
[OutputType([System.Diagnostics.FileVersionInfo])]
52+
param
53+
(
54+
[Parameter(Mandatory = $true)]
55+
[System.String]
56+
$FilePath,
57+
58+
[Parameter()]
59+
[System.Management.Automation.SwitchParameter]
60+
$Force
61+
)
62+
63+
$validProductNames = @(
64+
'Microsoft SQL Server Reporting Services'
65+
'Microsoft Power BI Report Server'
66+
)
67+
68+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_GettingVersionFromFile -f $FilePath)
69+
70+
$versionInfo = Get-FileVersion -Path $FilePath
71+
72+
if (-not $Force.IsPresent)
73+
{
74+
if ($versionInfo.ProductName -notin $validProductNames)
75+
{
76+
$errorMessage = $script:localizedData.Get_SqlDscRSPackage_InvalidProductName -f $versionInfo.ProductName, ($validProductNames -join "', '")
77+
78+
$PSCmdlet.ThrowTerminatingError(
79+
[System.Management.Automation.ErrorRecord]::new(
80+
$errorMessage,
81+
'GSDRSP0002',
82+
[System.Management.Automation.ErrorCategory]::InvalidArgument,
83+
$FilePath
84+
)
85+
)
86+
}
87+
}
88+
89+
Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_ReturningVersionInfo -f $versionInfo.ProductName, $versionInfo.ProductVersion)
90+
91+
return $versionInfo
92+
}

source/en-US/SqlServerDsc.strings.psd1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,9 @@ ConvertFrom-StringData @'
665665
## Get-SqlDscDateTime
666666
Get_SqlDscDateTime_RetrievingDateTime = Retrieving date and time using {0}(). (GSDD0001)
667667
Get_SqlDscDateTime_FailedToRetrieve = Failed to retrieve date and time using {0}(): {1} (GSDD0002)
668+
669+
## Get-SqlDscRSPackage
670+
Get_SqlDscRSPackage_GettingVersionFromFile = Getting version information from file '{0}'. (GSDRSP0001)
671+
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)
672+
Get_SqlDscRSPackage_ReturningVersionInfo = Returning version information for '{0}' version '{1}'. (GSDRSP0003)
668673
'@
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 a non-existing file' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') {
34+
It 'Should throw an error when the file does not exist' {
35+
{ Get-SqlDscRSPackage -FilePath 'C:\NonExistent\SQLServerReportingServices.exe' -ErrorAction 'Stop' } | Should -Throw
36+
}
37+
}
38+
39+
Context 'When getting package information for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
40+
BeforeAll {
41+
$script:temporaryFolder = Get-TemporaryFolder
42+
$script:reportingServicesExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'SQLServerReportingServices.exe'
43+
}
44+
45+
It 'Should return the package information for SSRS' {
46+
$result = Get-SqlDscRSPackage -FilePath $script:reportingServicesExecutable -ErrorAction 'Stop'
47+
48+
$result | Should -Not -BeNullOrEmpty
49+
$result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services'
50+
$result.FileVersion | Should -Not -BeNullOrEmpty
51+
$result.ProductVersion | Should -Not -BeNullOrEmpty
52+
}
53+
}
54+
55+
# cSpell: ignore PBIRS
56+
Context 'When getting package information for Power BI Report Server' -Tag @('Integration_PowerBI') {
57+
BeforeAll {
58+
$script:temporaryFolder = Get-TemporaryFolder
59+
$script:powerBIReportServerExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'PowerBIReportServer.exe'
60+
}
61+
62+
It 'Should return the package information for PBIRS' {
63+
$result = Get-SqlDscRSPackage -FilePath $script:powerBIReportServerExecutable -ErrorAction 'Stop'
64+
65+
$result | Should -Not -BeNullOrEmpty
66+
$result.ProductName | Should -Be 'Microsoft Power BI Report Server'
67+
$result.FileVersion | Should -Not -BeNullOrEmpty
68+
$result.ProductVersion | Should -Not -BeNullOrEmpty
69+
}
70+
}
71+
72+
Context 'When file has an invalid product name' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') {
73+
It 'Should throw an error without Force parameter' {
74+
# Use an executable that exists but has a different product name
75+
{ Get-SqlDscRSPackage -FilePath 'C:\Windows\System32\notepad.exe' -ErrorAction 'Stop' } | Should -Throw
76+
}
77+
78+
It 'Should return version information with Force parameter' {
79+
$result = Get-SqlDscRSPackage -FilePath 'C:\Windows\System32\notepad.exe' -Force -ErrorAction 'Stop'
80+
81+
$result | Should -Not -BeNullOrEmpty
82+
$result.FileVersion | Should -Not -BeNullOrEmpty
83+
}
84+
}
85+
86+
Context 'When using Force parameter to bypass validation' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
87+
BeforeAll {
88+
$script:temporaryFolder = Get-TemporaryFolder
89+
$script:reportingServicesExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'SQLServerReportingServices.exe'
90+
}
91+
92+
It 'Should return file version information with Force parameter' {
93+
$result = Get-SqlDscRSPackage -FilePath $script:reportingServicesExecutable -Force -ErrorAction 'Stop'
94+
95+
$result | Should -Not -BeNullOrEmpty
96+
$result.FileVersion | Should -Not -BeNullOrEmpty
97+
}
98+
}
99+
}

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)