Skip to content

Commit a86073b

Browse files
committed
Update changelog and improve error handling in RS IP Address command
1 parent be94b4f commit a86073b

5 files changed

Lines changed: 66 additions & 77 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
used with `Get-ChildItem` and `Get-Content` to access service logs, portal
2929
logs, and memory dumps.
3030
- Added public command `Get-SqlDscRSExecutionLog` to query execution log entries
31-
from the `ExecutionLog3` view in the report server database for SQL Server
32-
Reporting Services or Power BI Report Server. Supports filtering by date
33-
range, user name, report path, and maximum rows. Includes connection parameters
34-
for authentication including Credential, LoginType, Encrypt, and StatementTimeout.
31+
from the `ExecutionLog3` view in the report server database. Supports filtering
32+
by date range, user name, report path, and maximum rows. Includes connection
33+
parameters **Credential**, **LoginType**, **Encrypt**, and **StatementTimeout**.
3534
- Added public command `Test-SqlDscRSAccessible` to verify that SQL Server
3635
Reporting Services or Power BI Report Server web sites are accessible.
3736
Supports both CIM configuration input (with dynamic `-Site` parameter) and

source/Public/Get-SqlDscRSDatabaseInstallation.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
InstanceName, and IsInitialized.
4444
4545
.NOTES
46-
This command calls the WMI method `ListReportServersInDatabase`.
46+
This command calls the CIM/WMI provider method `ListReportServersInDatabase`
47+
using `Invoke-RsCimMethod`.
4748
4849
.LINK
4950
https://docs.microsoft.com/en-us/sql/reporting-services/wmi-provider-library-reference/configurationsetting-method-listreportserversindatabase

source/Public/Get-SqlDscRSIPAddress.ps1

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
`MSReportServer_ConfigurationSetting` CIM instance.
1010
1111
This command returns information about IP addresses that can be
12-
used for URL reservations and SSL bindings.
12+
used for URL reservations and SSL bindings. Each returned object
13+
includes the IP address, IP version (V4 or V6), and whether DHCP
14+
is enabled. If DHCP is enabled, the IP address is dynamic and should
15+
not be used for TLS bindings.
1316
1417
The configuration CIM instance can be obtained using the
1518
`Get-SqlDscRSConfiguration` command and passed via the pipeline.
@@ -20,31 +23,27 @@
2023
`Get-SqlDscRSConfiguration` command. This parameter accepts pipeline
2124
input.
2225
23-
.PARAMETER Lcid
24-
Specifies the language code identifier (LCID) for the request.
25-
If not specified, defaults to the operating system language. Common
26-
values include 1033 for English (US).
27-
2826
.EXAMPLE
2927
Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Get-SqlDscRSIPAddress
3028
3129
Gets all available IP addresses for the Reporting Services instance.
3230
3331
.EXAMPLE
3432
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
35-
Get-SqlDscRSIPAddress -Configuration $config -Lcid 1033
33+
Get-SqlDscRSIPAddress -Configuration $config | Where-Object -FilterScript { $_.IPVersion -eq 'V4' }
3634
37-
Gets available IP addresses with a specific LCID.
35+
Gets available IPv4 addresses for the Reporting Services instance.
3836
3937
.INPUTS
4038
`Microsoft.Management.Infrastructure.CimInstance`
4139
4240
Accepts MSReportServer_ConfigurationSetting CIM instance via pipeline.
4341
4442
.OUTPUTS
45-
`System.String`
43+
`[ReportServerIPAddress[]]`
4644
47-
Returns the IP addresses available on the machine.
45+
Returns an array of ReportServerIPAddress objects containing the IP
46+
address, IP version, and DHCP status.
4847
4948
.NOTES
5049
This command calls the WMI method `ListIPAddresses`.
@@ -56,57 +55,52 @@ function Get-SqlDscRSIPAddress
5655
{
5756
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')]
5857
[CmdletBinding()]
59-
[OutputType([System.String])]
58+
[OutputType([ReportServerIPAddress[]])]
6059
param
6160
(
6261
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
6362
[System.Object]
64-
$Configuration,
65-
66-
[Parameter()]
67-
[System.Int32]
68-
$Lcid
63+
$Configuration
6964
)
7065

7166
process
7267
{
7368
$instanceName = $Configuration.InstanceName
7469

75-
if (-not $PSBoundParameters.ContainsKey('Lcid'))
76-
{
77-
$Lcid = (Get-OperatingSystem).OSLanguage
78-
}
79-
8070
Write-Verbose -Message ($script:localizedData.Get_SqlDscRSIPAddress_Getting -f $instanceName)
8171

8272
$invokeRsCimMethodParameters = @{
8373
CimInstance = $Configuration
8474
MethodName = 'ListIPAddresses'
85-
Arguments = @{
86-
Lcid = $Lcid
87-
}
8875
}
8976

9077
try
9178
{
92-
$result = Invoke-RsCimMethod @invokeRsCimMethodParameters -ErrorAction 'Stop'
79+
$result = Invoke-RsCimMethod @invokeRsCimMethodParameters
9380

94-
# Return the IP addresses
95-
if ($result.IPAddress)
81+
# Return the IP addresses as ReportServerIPAddress objects
82+
if ($result.IPAddress -and $result.IPAddress.Count -gt 0)
9683
{
97-
return $result.IPAddress
84+
$ipAddressObjects = for ($i = 0; $i -lt $result.IPAddress.Count; $i++)
85+
{
86+
$ipAddressObject = [ReportServerIPAddress]::new()
87+
$ipAddressObject.IPAddress = $result.IPAddress[$i]
88+
$ipAddressObject.IPVersion = $result.IPVersion[$i]
89+
$ipAddressObject.IsDhcpEnabled = $result.IsDhcpEnabled[$i]
90+
91+
$ipAddressObject
92+
}
93+
94+
return $ipAddressObjects
9895
}
9996
}
10097
catch
10198
{
102-
$PSCmdlet.ThrowTerminatingError(
103-
[System.Management.Automation.ErrorRecord]::new(
104-
($script:localizedData.Get_SqlDscRSIPAddress_FailedToGet -f $instanceName, $_.Exception.Message),
105-
'GSRSIP0001',
106-
[System.Management.Automation.ErrorCategory]::InvalidOperation,
107-
$Configuration
108-
)
109-
)
99+
$errorMessage = $script:localizedData.Get_SqlDscRSIPAddress_FailedToGet -f $instanceName, $_.Exception.Message
100+
101+
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSIP0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
102+
103+
$PSCmdlet.ThrowTerminatingError($errorRecord)
110104
}
111105
}
112106
}

tests/Integration/Commands/Get-SqlDscRSIPAddress.Integration.Tests.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Describe 'Get-SqlDscRSIPAddress' {
3939

4040
$result | Should -Not -BeNullOrEmpty
4141
# Should at least contain the all-interfaces address
42-
$result | Should -Contain '0.0.0.0'
42+
$result.IPAddress | Should -Contain '0.0.0.0'
43+
$result.IPVersion | Should -Contain 'V4'
4344
}
4445
}
4546

@@ -49,7 +50,8 @@ Describe 'Get-SqlDscRSIPAddress' {
4950
$result = $configuration | Get-SqlDscRSIPAddress -ErrorAction 'Stop'
5051

5152
$result | Should -Not -BeNullOrEmpty
52-
$result | Should -Contain '0.0.0.0'
53+
$result.IPAddress | Should -Contain '0.0.0.0'
54+
$result.IPVersion | Should -Contain 'V4'
5355
}
5456
}
5557

@@ -59,7 +61,8 @@ Describe 'Get-SqlDscRSIPAddress' {
5961
$result = $configuration | Get-SqlDscRSIPAddress -ErrorAction 'Stop'
6062

6163
$result | Should -Not -BeNullOrEmpty
62-
$result | Should -Contain '0.0.0.0'
64+
$result.IPAddress | Should -Contain '0.0.0.0'
65+
$result.IPVersion | Should -Contain 'V4'
6366
}
6467
}
6568

@@ -69,7 +72,8 @@ Describe 'Get-SqlDscRSIPAddress' {
6972
$result = $configuration | Get-SqlDscRSIPAddress -ErrorAction 'Stop'
7073

7174
$result | Should -Not -BeNullOrEmpty
72-
$result | Should -Contain '0.0.0.0'
75+
$result.IPAddress | Should -Contain '0.0.0.0'
76+
$result.IPVersion | Should -Contain 'V4'
7377
}
7478
}
7579
}

tests/Unit/Public/Get-SqlDscRSIPAddress.Tests.ps1

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Describe 'Get-SqlDscRSIPAddress' {
4848
It 'Should have the correct parameters in parameter set <ExpectedParameterSetName>' -ForEach @(
4949
@{
5050
ExpectedParameterSetName = '__AllParameterSets'
51-
ExpectedParameters = '[-Configuration] <Object> [[-Lcid] <int>] [<CommonParameters>]'
51+
ExpectedParameters = '[-Configuration] <Object> [<CommonParameters>]'
5252
}
5353
) {
5454
$result = (Get-Command -Name 'Get-SqlDscRSIPAddress').ParameterSets |
@@ -69,26 +69,28 @@ Describe 'Get-SqlDscRSIPAddress' {
6969
InstanceName = 'SSRS'
7070
}
7171

72-
Mock -CommandName Get-OperatingSystem -MockWith {
73-
return [PSCustomObject] @{
74-
OSLanguage = 1033
75-
}
76-
}
77-
7872
Mock -CommandName Invoke-RsCimMethod -MockWith {
7973
return @{
80-
IPAddress = @('0.0.0.0', '192.168.1.1', '::')
74+
IPAddress = @('0.0.0.0', '192.168.1.1', '::')
75+
IPVersion = @('V4', 'V4', 'V6')
76+
IsDhcpEnabled = @($false, $true, $false)
8177
}
8278
}
8379
}
8480

85-
It 'Should return IP addresses' {
81+
It 'Should return IP addresses as ReportServerIPAddress objects' {
8682
$result = $mockCimInstance | Get-SqlDscRSIPAddress
8783

8884
$result | Should -HaveCount 3
89-
$result | Should -Contain '0.0.0.0'
90-
$result | Should -Contain '192.168.1.1'
91-
$result | Should -Contain '::'
85+
$result[0].IPAddress | Should -Be '0.0.0.0'
86+
$result[0].IPVersion | Should -Be 'V4'
87+
$result[0].IsDhcpEnabled | Should -BeFalse
88+
$result[1].IPAddress | Should -Be '192.168.1.1'
89+
$result[1].IPVersion | Should -Be 'V4'
90+
$result[1].IsDhcpEnabled | Should -BeTrue
91+
$result[2].IPAddress | Should -Be '::'
92+
$result[2].IPVersion | Should -Be 'V6'
93+
$result[2].IsDhcpEnabled | Should -BeFalse
9294

9395
Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
9496
$MethodName -eq 'ListIPAddresses'
@@ -102,15 +104,11 @@ Describe 'Get-SqlDscRSIPAddress' {
102104
InstanceName = 'SSRS'
103105
}
104106

105-
Mock -CommandName Get-OperatingSystem -MockWith {
106-
return [PSCustomObject] @{
107-
OSLanguage = 1033
108-
}
109-
}
110-
111107
Mock -CommandName Invoke-RsCimMethod -MockWith {
112108
return @{
113-
IPAddress = @()
109+
IPAddress = @()
110+
IPVersion = @()
111+
IsDhcpEnabled = @()
114112
}
115113
}
116114
}
@@ -130,12 +128,6 @@ Describe 'Get-SqlDscRSIPAddress' {
130128
InstanceName = 'SSRS'
131129
}
132130

133-
Mock -CommandName Get-OperatingSystem -MockWith {
134-
return [PSCustomObject] @{
135-
OSLanguage = 1033
136-
}
137-
}
138-
139131
Mock -CommandName Invoke-RsCimMethod -MockWith {
140132
throw 'Method ListIPAddresses() failed with an error.'
141133
}
@@ -152,15 +144,11 @@ Describe 'Get-SqlDscRSIPAddress' {
152144
InstanceName = 'SSRS'
153145
}
154146

155-
Mock -CommandName Get-OperatingSystem -MockWith {
156-
return [PSCustomObject] @{
157-
OSLanguage = 1033
158-
}
159-
}
160-
161147
Mock -CommandName Invoke-RsCimMethod -MockWith {
162148
return @{
163-
IPAddress = @('0.0.0.0')
149+
IPAddress = @('0.0.0.0')
150+
IPVersion = @('V4')
151+
IsDhcpEnabled = @($false)
164152
}
165153
}
166154
}
@@ -169,6 +157,9 @@ Describe 'Get-SqlDscRSIPAddress' {
169157
$result = Get-SqlDscRSIPAddress -Configuration $mockCimInstance
170158

171159
$result | Should -HaveCount 1
160+
$result[0].IPAddress | Should -Be '0.0.0.0'
161+
$result[0].IPVersion | Should -Be 'V4'
162+
$result[0].IsDhcpEnabled | Should -BeFalse
172163

173164
Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1
174165
}

0 commit comments

Comments
 (0)