Skip to content

Commit e86a3d5

Browse files
authored
Fix to be compliant with QA tests (#2162)
1 parent 59c5c40 commit e86a3d5

11 files changed

+30
-49
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
ValidateSet for the Edition property.
2424
- Fixed commands continuing execution after `Assert-ElevatedUser` elevation
2525
errors by setting `$ErrorActionPreference = 'Stop'` [issue #2070](https://github.com/dsccommunity/SqlServerDsc/issues/2070)
26+
- Fixed incorrect array-return syntax in several public `Get-*` commands by
27+
removing a leading comma in return statements which could cause incorrect
28+
output and ScriptAnalyzer warnings: `Get-SqlDscAudit`,
29+
`Get-SqlDscConfigurationOption`, `Get-SqlDscDatabasePermission`,
30+
`Get-SqlDscServerPermission`, and `Get-SqlDscTraceFlag`.
31+
- New-SqlDscDatabase: use `New-ArgumentException` instead of
32+
`New-InvalidArgumentException` for parameter validation errors.
2633

2734
### Added
2835

@@ -131,6 +138,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
131138
- Improved markdown, pester, powershell, and changelog instructions.
132139
- Fixed `Ignore` that seems in edge-cases fail.
133140
- Improved markdown and changelog instructions.
141+
- `RequiredModules.psd1`
142+
- Updated `DscResource.Test` dependency to `latest` (was pinned to `0.17.2`).
143+
- Examples
144+
- `source/Examples/Resources/SqlSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1`
145+
- Removed redundant `$SqlAdministratorCredential` parameter from example
146+
configuration.
134147

135148
## [17.1.0] - 2025-05-22
136149

RequiredModules.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Sampler = 'latest'
2929
'Sampler.GitHubTasks' = 'latest'
3030
MarkdownLinkCheck = 'latest'
31-
'DscResource.Test' = '0.17.2'
31+
'DscResource.Test' = 'latest'
3232
xDscResourceDesigner = 'latest'
3333

3434
# Build dependencies needed for using the module

source/Examples/Resources/SqlSetup/5-InstallNamedInstanceInFailoverClusterSecondNode.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ Configuration Example
3636
[System.Management.Automation.PSCredential]
3737
$SqlInstallCredential,
3838

39-
[Parameter()]
40-
[ValidateNotNullOrEmpty()]
41-
[System.Management.Automation.PSCredential]
42-
$SqlAdministratorCredential = $SqlInstallCredential,
43-
4439
[Parameter(Mandatory = $true)]
4540
[ValidateNotNullOrEmpty()]
4641
[System.Management.Automation.PSCredential]

source/Public/Get-SqlDscAudit.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
Get the audit named **MyFileAudit**.
2626
2727
.OUTPUTS
28-
`[Microsoft.SqlServer.Management.Smo.Audit]`
28+
`[Microsoft.SqlServer.Management.Smo.Audit[]]`
29+
Array of SMO Audit objects from the target SQL Server instance.
2930
#>
3031
function Get-SqlDscAudit
3132
{
32-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '', Justification = 'Because the rule does not understands that the command returns [System.String[]] when using , (comma) in the return statement')]
3333
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
3434
[OutputType([Microsoft.SqlServer.Management.Smo.Audit[]])]
3535
[CmdletBinding()]
@@ -62,7 +62,7 @@ function Get-SqlDscAudit
6262
{
6363
$auditObject = $ServerObject.Audits[$Name]
6464

65-
if (-not $AuditObject)
65+
if (-not $auditObject)
6666
{
6767
$missingAuditMessage = $script:localizedData.Audit_Missing -f $Name
6868

@@ -81,6 +81,6 @@ function Get-SqlDscAudit
8181
$auditObject = $ServerObject.Audits
8282
}
8383

84-
return , [Microsoft.SqlServer.Management.Smo.Audit[]] $auditObject
84+
return [Microsoft.SqlServer.Management.Smo.Audit[]] $auditObject
8585
}
8686
}

source/Public/Get-SqlDscConfigurationOption.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
3232
.OUTPUTS
3333
`[Microsoft.SqlServer.Management.Smo.ConfigProperty[]]`
34+
Array of SMO ConfigProperty objects representing server configuration options.
3435
#>
3536
function Get-SqlDscConfigurationOption
3637
{
37-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '', Justification = 'Because the rule does not understands that the command returns [System.String[]] when using , (comma) in the return statement')]
3838
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
3939
[OutputType([Microsoft.SqlServer.Management.Smo.ConfigProperty[]])]
4040
[CmdletBinding()]
@@ -58,12 +58,12 @@ function Get-SqlDscConfigurationOption
5858
if ($Refresh.IsPresent)
5959
{
6060
# Make sure the configuration option values are up-to-date.
61-
$serverObject.Configuration.Refresh()
61+
$ServerObject.Configuration.Refresh()
6262
}
6363

6464
if ($PSBoundParameters.ContainsKey('Name'))
6565
{
66-
$configurationOption = $serverObject.Configuration.Properties |
66+
$configurationOption = $ServerObject.Configuration.Properties |
6767
Where-Object -FilterScript {
6868
$_.DisplayName -like $Name
6969
}
@@ -84,10 +84,10 @@ function Get-SqlDscConfigurationOption
8484
}
8585
else
8686
{
87-
$configurationOption = $serverObject.Configuration.Properties.ForEach({ $_ })
87+
$configurationOption = $ServerObject.Configuration.Properties.ForEach({ $_ })
8888
}
8989

90-
return , [Microsoft.SqlServer.Management.Smo.ConfigProperty[]] (
90+
return [Microsoft.SqlServer.Management.Smo.ConfigProperty[]] (
9191
$configurationOption |
9292
Sort-Object -Property 'DisplayName'
9393
)

source/Public/Get-SqlDscDatabasePermission.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#>
3737
function Get-SqlDscDatabasePermission
3838
{
39-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '', Justification = 'Because the rule does not understands that the command returns [System.String[]] when using , (comma) in the return statement')]
4039
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
4140
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('AvoidThrowOutsideOfTry', '', Justification = 'Because the code throws based on an prior expression')]
4241
[CmdletBinding()]
@@ -97,6 +96,6 @@ function Get-SqlDscDatabasePermission
9796
Write-Error -Message $missingDatabaseMessage -Category 'InvalidOperation' -ErrorId 'GSDDP0002' -TargetObject $DatabaseName
9897
}
9998

100-
return , [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] $getSqlDscDatabasePermissionResult
99+
return [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] $getSqlDscDatabasePermissionResult
101100
}
102101
}

source/Public/Get-SqlDscServerPermission.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
#>
9696
function Get-SqlDscServerPermission
9797
{
98-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '', Justification = 'Because the rule does not understands that the command returns [System.String[]] when using , (comma) in the return statement')]
9998
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
10099
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('AvoidThrowOutsideOfTry', '', Justification = 'Because the code throws based on an prior expression')]
101100
[CmdletBinding(DefaultParameterSetName = 'ByName')]
@@ -196,6 +195,6 @@ function Get-SqlDscServerPermission
196195
Write-Error -Message $missingPrincipalMessage -Category 'InvalidOperation' -ErrorId 'GSDSP0001' -TargetObject $principalName
197196
}
198197

199-
return , [Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[]] $getSqlDscServerPermissionResult
198+
return [Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[]] $getSqlDscServerPermissionResult
200199
}
201200
}

source/Public/Get-SqlDscTraceFlag.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#>
4646
function Get-SqlDscTraceFlag
4747
{
48-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '', Justification = 'Because the rule does not understands that the command returns [System.UInt32[]] when using , (comma) in the return statement')]
4948
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the rule does not yet support parsing the code when a parameter type is not available. The ScriptAnalyzer rule UseSyntacticallyCorrectExamples will always error in the editor due to https://github.com/indented-automation/Indented.ScriptAnalyzerRules/issues/8.')]
5049
[OutputType([System.UInt32[]])]
5150
[CmdletBinding(DefaultParameterSetName = 'ByServerName')]
@@ -83,5 +82,5 @@ function Get-SqlDscTraceFlag
8382
$script:localizedData.TraceFlag_Get_DebugReturningTraceFlags -f $MyInvocation.MyCommand, ($traceFlags -join ', ')
8483
)
8584

86-
return , [System.UInt32[]] $traceFlags
85+
return [System.UInt32[]] $traceFlags
8786
}

source/Public/New-SqlDscDatabase.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function New-SqlDscDatabase
139139
if ($CompatibilityLevel -notin $supportedCompatibilityLevels.$($ServerObject.VersionMajor))
140140
{
141141
$errorMessage = $script:localizedData.Database_InvalidCompatibilityLevel -f $CompatibilityLevel, $ServerObject.InstanceName
142-
New-InvalidArgumentException -ArgumentName 'CompatibilityLevel' -Message $errorMessage
142+
New-ArgumentException -ArgumentName 'CompatibilityLevel' -Message $errorMessage
143143
}
144144
}
145145

@@ -149,7 +149,7 @@ function New-SqlDscDatabase
149149
if ($Collation -notin $ServerObject.EnumCollations().Name)
150150
{
151151
$errorMessage = $script:localizedData.Database_InvalidCollation -f $Collation, $ServerObject.InstanceName
152-
New-InvalidArgumentException -ArgumentName 'Collation' -Message $errorMessage
152+
New-ArgumentException -ArgumentName 'Collation' -Message $errorMessage
153153
}
154154
}
155155

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration
233233
$result = $loginObjects | Get-SqlDscServerPermission
234234

235235
$result | Should -Not -BeNullOrEmpty
236-
$result | Should -BeOfType [Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[]]
236+
$result | Should -BeOfType [Microsoft.SqlServer.Management.Smo.ServerPermissionInfo]
237237
$result.Count | Should -BeGreaterThan 1
238238
}
239239
}
@@ -271,7 +271,7 @@ Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration
271271
$result = $roleObjects | Get-SqlDscServerPermission
272272

273273
$result | Should -Not -BeNullOrEmpty
274-
$result | Should -BeOfType [Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[]]
274+
$result | Should -BeOfType [Microsoft.SqlServer.Management.Smo.ServerPermissionInfo]
275275
$result.Count | Should -BeGreaterThan 1
276276
}
277277
}

0 commit comments

Comments
 (0)