Skip to content

Commit 70c5846

Browse files
authored
Set-SqlDscRSSmtpConfiguration: Add new command (#2411)
1 parent 10871a9 commit 70c5846

31 files changed

Lines changed: 718 additions & 96 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
244244
by calling the `InitializeReportServer` CIM method. Used to complete initial
245245
configuration after database and URL setup
246246
([issue #2014](https://github.com/dsccommunity/SqlServerDsc/issues/2014)).
247+
- Added public command `Set-SqlDscRSSmtpConfiguration` to configure SMTP
248+
settings for Reporting Services email delivery. Wraps the `SetEmailConfiguration`
249+
CIM method.
247250
- Added public commands `Set-SqlDscRSUnattendedExecutionAccount` and
248251
`Remove-SqlDscRSUnattendedExecutionAccount` to manage the unattended execution
249252
account for Reporting Services. These wrap the `SetUnattendedExecutionAccount`

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ stages:
596596
'tests/Integration/Commands/Post.ServiceAccountChange.SQL2019-2022.RS.Integration.Tests.ps1'
597597
# Group 7
598598
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
599+
'tests/Integration/Commands/Set-SqlDscRSSmtpConfiguration.Integration.Tests.ps1'
599600
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
600601
# Group 8
601602
'tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1'
@@ -698,6 +699,7 @@ stages:
698699
'tests/Integration/Commands/Post.ServiceAccountChange.PowerBI.RS.Integration.Tests.ps1'
699700
# Group 7
700701
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
702+
'tests/Integration/Commands/Set-SqlDscRSSmtpConfiguration.Integration.Tests.ps1'
701703
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
702704
# Group 8
703705
'tests/Integration/Commands/Repair-SqlDscPowerBIReportServer.Integration.Tests.ps1'
@@ -786,6 +788,7 @@ stages:
786788
'tests/Integration/Commands/Set-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
787789
# Group 7
788790
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
791+
'tests/Integration/Commands/Set-SqlDscRSSmtpConfiguration.Integration.Tests.ps1'
789792
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
790793
)
791794
name: test

source/Public/Add-SqlDscRSSslCertificateBinding.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ function Add-SqlDscRSSslCertificateBinding
171171
}
172172
catch
173173
{
174-
$errorMessage = $script:localizedData.Add_SqlDscRSSslCertificateBinding_FailedToAdd -f $instanceName, $_.Exception.Message
174+
$errorMessage = $script:localizedData.Add_SqlDscRSSslCertificateBinding_FailedToAdd -f $instanceName
175175

176-
$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru
176+
$exception = New-Exception -Message $errorMessage -ErrorRecord $_
177177

178178
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'ASRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
179179

source/Public/Add-SqlDscRSUrlReservation.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ function Add-SqlDscRSUrlReservation
155155
}
156156
catch
157157
{
158-
$errorMessage = $script:localizedData.Add_SqlDscRSUrlReservation_FailedToAdd -f $instanceName, $_.Exception.Message
158+
$errorMessage = $script:localizedData.Add_SqlDscRSUrlReservation_FailedToAdd -f $instanceName
159159

160-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'ASRUR0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
160+
$exception = New-Exception -Message $errorMessage -ErrorRecord $_
161+
162+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'ASRUR0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
161163

162164
$PSCmdlet.ThrowTerminatingError($errorRecord)
163165
}

source/Public/Get-SqlDscRSConfigFile.ps1

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ function Get-SqlDscRSConfigFile
139139
{
140140
$errorMessage = $script:localizedData.Get_SqlDscRSConfigFile_InstanceNotFound -f $InstanceName
141141

142-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCF0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
142+
$exception = New-Exception -Message $errorMessage
143+
144+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCF0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
143145

144146
$PSCmdlet.ThrowTerminatingError($errorRecord)
145147
}
@@ -148,7 +150,9 @@ function Get-SqlDscRSConfigFile
148150
{
149151
$errorMessage = $script:localizedData.Get_SqlDscRSConfigFile_ConfigFilePathNotFound -f $InstanceName
150152

151-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCF0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
153+
$exception = New-Exception -Message $errorMessage
154+
155+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCF0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
152156

153157
$PSCmdlet.ThrowTerminatingError($errorRecord)
154158
}
@@ -164,7 +168,9 @@ function Get-SqlDscRSConfigFile
164168
{
165169
$errorMessage = $script:localizedData.Get_SqlDscRSConfigFile_ConfigFilePathNotFound -f $SetupConfiguration.InstanceName
166170

167-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCF0002' -ErrorCategory 'ObjectNotFound' -TargetObject $SetupConfiguration.InstanceName
171+
$exception = New-Exception -Message $errorMessage
172+
173+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCF0002' -ErrorCategory 'ObjectNotFound' -TargetObject $SetupConfiguration.InstanceName
168174

169175
$PSCmdlet.ThrowTerminatingError($errorRecord)
170176
}
@@ -180,7 +186,9 @@ function Get-SqlDscRSConfigFile
180186
{
181187
$errorMessage = $script:localizedData.Get_SqlDscRSConfigFile_FileNotFound -f $Path
182188

183-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCF0004' -ErrorCategory 'ObjectNotFound' -TargetObject $Path
189+
$exception = New-Exception -Message $errorMessage
190+
191+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCF0004' -ErrorCategory 'ObjectNotFound' -TargetObject $Path
184192

185193
$PSCmdlet.ThrowTerminatingError($errorRecord)
186194
}
@@ -197,9 +205,11 @@ function Get-SqlDscRSConfigFile
197205
}
198206
catch
199207
{
200-
$errorMessage = $script:localizedData.Get_SqlDscRSConfigFile_FailedToReadConfigFile -f $configFilePath, $_.Exception.Message
208+
$errorMessage = $script:localizedData.Get_SqlDscRSConfigFile_FailedToReadConfigFile -f $configFilePath
209+
210+
$exception = New-Exception -Message $errorMessage -ErrorRecord $_
201211

202-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru) -ErrorId 'GSRSCF0003' -ErrorCategory 'ReadError' -TargetObject $configFilePath
212+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCF0003' -ErrorCategory 'ReadError' -TargetObject $configFilePath
203213

204214
$PSCmdlet.ThrowTerminatingError($errorRecord)
205215
}

source/Public/Get-SqlDscRSConfiguration.ps1

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ function Get-SqlDscRSConfiguration
120120
{
121121
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_InstanceNotFound -f $InstanceName
122122

123-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCD0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
123+
$exception = New-Exception -Message $errorMessage
124+
125+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCD0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
124126

125127
$PSCmdlet.ThrowTerminatingError($errorRecord)
126128
}
@@ -129,7 +131,9 @@ function Get-SqlDscRSConfiguration
129131
{
130132
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_VersionNotFound -f $InstanceName
131133

132-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCD0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
134+
$exception = New-Exception -Message $errorMessage
135+
136+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCD0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
133137

134138
$PSCmdlet.ThrowTerminatingError($errorRecord)
135139
}
@@ -167,9 +171,11 @@ function Get-SqlDscRSConfiguration
167171
}
168172
catch
169173
{
170-
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName, $_.Exception.Message
174+
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName
171175

172-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru) -ErrorId 'GSRSCD0003' -ErrorCategory 'InvalidOperation' -TargetObject $InstanceName
176+
$exception = New-Exception -Message $errorMessage -ErrorRecord $_
177+
178+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCD0003' -ErrorCategory 'InvalidOperation' -TargetObject $InstanceName
173179

174180
$PSCmdlet.ThrowTerminatingError($errorRecord)
175181
}
@@ -197,7 +203,9 @@ function Get-SqlDscRSConfiguration
197203
{
198204
$errorMessage = $script:localizedData.Get_SqlDscRSConfiguration_ConfigurationNotFound -f $InstanceName
199205

200-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSCD0004' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
206+
$exception = New-Exception -Message $errorMessage
207+
208+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSCD0004' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
201209

202210
$PSCmdlet.ThrowTerminatingError($errorRecord)
203211
}

source/Public/Get-SqlDscRSExecutionLog.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ ORDER BY TimeStart DESC
298298
}
299299
catch
300300
{
301-
$errorMessage = $script:localizedData.Get_SqlDscRSExecutionLog_QueryFailed -f $InstanceName, $_.Exception.Message
301+
$errorMessage = $script:localizedData.Get_SqlDscRSExecutionLog_QueryFailed -f $InstanceName
302302

303303
Write-Error -Message $errorMessage -Category 'InvalidOperation' -ErrorId 'GSRSEL0001' -TargetObject $InstanceName -Exception $_.Exception
304304

source/Public/Get-SqlDscRSIPAddress.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ function Get-SqlDscRSIPAddress
9696
}
9797
catch
9898
{
99-
$errorMessage = $script:localizedData.Get_SqlDscRSIPAddress_FailedToGet -f $instanceName, $_.Exception.Message
99+
$errorMessage = $script:localizedData.Get_SqlDscRSIPAddress_FailedToGet -f $instanceName
100100

101-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSIP0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
101+
$exception = New-Exception -Message $errorMessage -ErrorRecord $_
102+
103+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSIP0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
102104

103105
$PSCmdlet.ThrowTerminatingError($errorRecord)
104106
}

source/Public/Get-SqlDscRSLogPath.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ function Get-SqlDscRSLogPath
102102
{
103103
$errorMessage = $script:localizedData.Get_SqlDscRSLogPath_InstanceNotFound -f $InstanceName
104104

105-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSLP0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
105+
$exception = New-Exception -Message $errorMessage
106+
107+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSLP0001' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
106108

107109
$PSCmdlet.ThrowTerminatingError($errorRecord)
108110
}
@@ -111,7 +113,9 @@ function Get-SqlDscRSLogPath
111113
{
112114
$errorMessage = $script:localizedData.Get_SqlDscRSLogPath_LogPathNotFound -f $InstanceName
113115

114-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'GSRSLP0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
116+
$exception = New-Exception -Message $errorMessage
117+
118+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSLP0002' -ErrorCategory 'ObjectNotFound' -TargetObject $InstanceName
115119

116120
$PSCmdlet.ThrowTerminatingError($errorRecord)
117121
}

source/Public/Get-SqlDscRSPackage.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ function Get-SqlDscRSPackage
7474
{
7575
$errorMessage = $script:localizedData.Get_SqlDscRSPackage_InvalidProductName -f $versionInfo.ProductName, ($validProductNames -join "', '")
7676

77-
$PSCmdlet.ThrowTerminatingError(
78-
[System.Management.Automation.ErrorRecord]::new(
79-
$errorMessage,
80-
'GSDRSP0002',
81-
[System.Management.Automation.ErrorCategory]::InvalidArgument,
82-
$FilePath
83-
)
84-
)
77+
$exception = New-Exception -Message $errorMessage
78+
79+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSDRSP0002' -ErrorCategory 'InvalidArgument' -TargetObject $FilePath
80+
81+
$PSCmdlet.ThrowTerminatingError($errorRecord)
8582
}
8683
}
8784

0 commit comments

Comments
 (0)