Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added public command `Get-SqlDscRSPackage` to retrieve package information for
SQL Server Reporting Services or Power BI Report Server. Supports getting version
information from an executable file
([issue #2082](https://github.com/dsccommunity/SqlServerDsc/issues/2082)).
- Added public command `Get-SqlDscBackupFileList` to read the list of database
files contained in a SQL Server backup file. Useful for planning file
relocations during restore operations ([issue #2026](https://github.com/dsccommunity/SqlServerDsc/issues/2026)).
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ stages:
'tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1'
# Group 2
'tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscRSPackage.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscRSSetupConfiguration.Integration.Tests.ps1'
'tests/Integration/Commands/Test-SqlDscRSInstalled.Integration.Tests.ps1'
# Group 8
Expand Down Expand Up @@ -596,6 +597,7 @@ stages:
'tests/Integration/Commands/Install-SqlDscPowerBIReportServer.Integration.Tests.ps1'
# Group 2
'tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscRSPackage.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscRSSetupConfiguration.Integration.Tests.ps1'
'tests/Integration/Commands/Test-SqlDscRSInstalled.Integration.Tests.ps1'
# Group 8
Expand Down
92 changes: 92 additions & 0 deletions source/Public/Get-SqlDscRSPackage.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<#
.SYNOPSIS
Gets package information for SQL Server Reporting Services or Power BI
Report Server.

.DESCRIPTION
Gets package information for a SQL Server Reporting Services or Power BI
Report Server executable file. The command returns file version information
including product name, product version, file version, and other
version-related metadata.

.PARAMETER FilePath
Specifies the path to the executable file to return version information for.
The file must have a product name matching either 'Microsoft SQL Server
Reporting Services' or 'Microsoft Power BI Report Server'.

.PARAMETER Force
If specified, the ProductName validation is skipped. This allows retrieving
version information for executables with different product names.

.EXAMPLE
Get-SqlDscRSPackage -FilePath 'E:\SQLServerReportingServices.exe'

Returns package information from the specified SQL Server Reporting Services
executable file.

.EXAMPLE
Get-SqlDscRSPackage -FilePath 'E:\PBIReportServer.exe'

Returns package information from the specified Power BI Report Server
executable file.

.EXAMPLE
Get-SqlDscRSPackage -FilePath 'E:\CustomReportServer.exe' -Force

Returns package information from the specified executable file without
validating the product name.

.INPUTS
None.

.OUTPUTS
`System.Diagnostics.FileVersionInfo`

Returns the file version information for the package.
#>
function Get-SqlDscRSPackage
{
# cSpell: ignore PBIRS
[CmdletBinding()]
[OutputType([System.Diagnostics.FileVersionInfo])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$FilePath,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$Force
)

$validProductNames = @(
'Microsoft SQL Server Reporting Services'
'Microsoft Power BI Report Server'
)

Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_GettingVersionFromFile -f $FilePath)

$versionInfo = Get-FileVersion -Path $FilePath

if (-not $Force.IsPresent)
{
if ($versionInfo.ProductName -notin $validProductNames)
{
$errorMessage = $script:localizedData.Get_SqlDscRSPackage_InvalidProductName -f $versionInfo.ProductName, ($validProductNames -join "', '")

$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$errorMessage,
'GSDRSP0002',
[System.Management.Automation.ErrorCategory]::InvalidArgument,
$FilePath
)
)
}
}

Write-Debug -Message ($script:localizedData.Get_SqlDscRSPackage_ReturningVersionInfo -f $versionInfo.ProductName, $versionInfo.ProductVersion)

return $versionInfo
}
5 changes: 5 additions & 0 deletions source/en-US/SqlServerDsc.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,9 @@ ConvertFrom-StringData @'
## Get-SqlDscDateTime
Get_SqlDscDateTime_RetrievingDateTime = Retrieving date and time using {0}(). (GSDD0001)
Get_SqlDscDateTime_FailedToRetrieve = Failed to retrieve date and time using {0}(): {1} (GSDD0002)

## Get-SqlDscRSPackage
Get_SqlDscRSPackage_GettingVersionFromFile = Getting version information from file '{0}'. (GSDRSP0001)
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)
Get_SqlDscRSPackage_ReturningVersionInfo = Returning version information for '{0}' version '{1}'. (GSDRSP0003)
'@
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
try
{
if (-not (Get-Module -Name 'DscResource.Test'))
{
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
}

# If the dependencies have not been resolved, this will throw an error.
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
}
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
}
}

BeforeAll {
$script:moduleName = 'SqlServerDsc'

Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
}

Describe 'Get-SqlDscRSPackage' {
Context 'When getting package information for a non-existing file' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') {
It 'Should throw an error when the file does not exist' {
{ Get-SqlDscRSPackage -FilePath 'C:\NonExistent\SQLServerReportingServices.exe' -ErrorAction 'Stop' } | Should -Throw
}
}

Context 'When getting package information for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
BeforeAll {
$script:temporaryFolder = Get-TemporaryFolder
$script:reportingServicesExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'SQLServerReportingServices.exe'
}

It 'Should return the package information for SSRS' {
$result = Get-SqlDscRSPackage -FilePath $script:reportingServicesExecutable -ErrorAction 'Stop'

$result | Should -Not -BeNullOrEmpty
$result.ProductName | Should -Be 'Microsoft SQL Server Reporting Services'
$result.FileVersion | Should -Not -BeNullOrEmpty
$result.ProductVersion | Should -Not -BeNullOrEmpty
}
}

# cSpell: ignore PBIRS
Context 'When getting package information for Power BI Report Server' -Tag @('Integration_PowerBI') {
BeforeAll {
$script:temporaryFolder = Get-TemporaryFolder
$script:powerBIReportServerExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'PowerBIReportServer.exe'
}

It 'Should return the package information for PBIRS' {
$result = Get-SqlDscRSPackage -FilePath $script:powerBIReportServerExecutable -ErrorAction 'Stop'

$result | Should -Not -BeNullOrEmpty
$result.ProductName | Should -Be 'Microsoft Power BI Report Server'
$result.FileVersion | Should -Not -BeNullOrEmpty
$result.ProductVersion | Should -Not -BeNullOrEmpty
}
}

Context 'When file has an invalid product name' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS', 'Integration_PowerBI') {
It 'Should throw an error without Force parameter' {
# Use an executable that exists but has a different product name
{ Get-SqlDscRSPackage -FilePath 'C:\Windows\System32\notepad.exe' -ErrorAction 'Stop' } | Should -Throw
}

It 'Should return version information with Force parameter' {
$result = Get-SqlDscRSPackage -FilePath 'C:\Windows\System32\notepad.exe' -Force -ErrorAction 'Stop'

$result | Should -Not -BeNullOrEmpty
$result.FileVersion | Should -Not -BeNullOrEmpty
}
}

Context 'When using Force parameter to bypass validation' -Tag @('Integration_SQL2017_RS', 'Integration_SQL2019_RS', 'Integration_SQL2022_RS') {
BeforeAll {
$script:temporaryFolder = Get-TemporaryFolder
$script:reportingServicesExecutable = Join-Path -Path $script:temporaryFolder -ChildPath 'SQLServerReportingServices.exe'
}

It 'Should return file version information with Force parameter' {
$result = Get-SqlDscRSPackage -FilePath $script:reportingServicesExecutable -Force -ErrorAction 'Stop'

$result | Should -Not -BeNullOrEmpty
$result.FileVersion | Should -Not -BeNullOrEmpty
}
}
}
2 changes: 2 additions & 0 deletions tests/Integration/Commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
Import-SqlDscPreferredModule | 0 | - | - | -
Install-SqlDscReportingService | 1 | 0 (Prerequisites) | - | SSRS instance
Get-SqlDscInstalledInstance | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
Get-SqlDscRSPackage | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
Get-SqlDscRSSetupConfiguration | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
Test-SqlDscRSInstalled | 2 | 1 (Install-SqlDscReportingService), 0 (Prerequisites) | SSRS | -
Repair-SqlDscReportingService | 8 | 1 (Install-SqlDscReportingService) | SSRS | -
Expand All @@ -180,6 +181,7 @@ Save-SqlDscSqlServerMediaFile | 0 | - | - | Downloads SQL Server media files
Import-SqlDscPreferredModule | 0 | - | - | -
Install-SqlDscPowerBIReportServer | 1 | 0 (Prerequisites) | - | PBIRS instance
Get-SqlDscInstalledInstance | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
Get-SqlDscRSPackage | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
Get-SqlDscRSSetupConfiguration | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
Test-SqlDscRSInstalled | 2 | 1 (Install-SqlDscPowerBIReportServer), 0 (Prerequisites) | PBIRS | -
Repair-SqlDscPowerBIReportServer | 8 | 1 (Install-SqlDscPowerBIReportServer) | PBIRS | -
Expand Down
22 changes: 21 additions & 1 deletion tests/QA/ScriptAnalyzer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,27 @@ BeforeDiscovery {
(from Indented.ScriptAnalyzerRules) can properly parse parameters that uses SMO types,
e.g. [Microsoft.SqlServer.Management.Smo.Server].
#>
Add-Type -Path "$PSScriptRoot/../Unit/Stubs/SMO.cs" -ReferencedAssemblies 'System.Data', 'System.Xml'
if ($IsLinux -or $IsMacOS)
{
# .NET Core requires different assemblies than .NET Framework
$referencedAssemblies = @(
'System.Collections'
'System.Collections.Specialized'
'System.Data.Common'
'System.Linq'
'System.Net.Primitives'
'netstandard'
)
}
else
{
$referencedAssemblies = @(
'System.Data'
'System.Xml'
)
}

Add-Type -Path "$PSScriptRoot/../Unit/Stubs/SMO.cs" -ReferencedAssemblies $referencedAssemblies

$repositoryPath = Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '../..')
$sourcePath = Join-Path -Path $repositoryPath -ChildPath 'source'
Expand Down
Loading
Loading