diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e96836d..97e093a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Re-enable integration tests for dbatools. - Bumped dbatools to v2.0.1 for the integration tests. +### fixed + +- `Import-SqlDscPreferredModule` + - Now when parameter `Force` is passed the command correctly invoke + `Get-SqlDscPreferredModule` using the parameter `Refresh`. + ## [16.3.1] - 2023-05-06 ### Changed diff --git a/source/Public/Import-SqlDscPreferredModule.ps1 b/source/Public/Import-SqlDscPreferredModule.ps1 index 9339c7722..23fa1b69f 100644 --- a/source/Public/Import-SqlDscPreferredModule.ps1 +++ b/source/Public/Import-SqlDscPreferredModule.ps1 @@ -65,6 +65,11 @@ function Import-SqlDscPreferredModule $getSqlDscPreferredModuleParameters.Name = @($Name, 'SQLPS') } + if ($PSBoundParameters.ContainsKey('Force')) + { + $getSqlDscPreferredModuleParameters.Refresh = $true + } + $availableModuleName = Get-SqlDscPreferredModule @getSqlDscPreferredModuleParameters if ($Force.IsPresent) diff --git a/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 b/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 index 35b68b4cc..0d3156308 100644 --- a/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 +++ b/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 @@ -236,7 +236,10 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { It 'Should import the SqlServer module without throwing' { { Import-SqlDscPreferredModule -Force } | Should -Not -Throw - Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It + Should -Invoke -CommandName Get-SqlDscPreferredModule -ParameterFilter { + $PesterBoundParameters.ContainsKey('Refresh') -and $Refresh -eq $true + } -Exactly -Times 1 -Scope It + Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It Should -Invoke -CommandName Pop-Location -Exactly -Times 1 -Scope It Should -Invoke -CommandName Remove-Module -Exactly -Times 1 -Scope It