From d9a84f43075a1a8a236a0c829db15b92eaecbaf5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 6 May 2023 11:33:47 +0200 Subject: [PATCH] `Import-SqlDscPreferredModule`: Fix checking that SQLPS is loaded (#1929) - `Import-SqlDscPreferredModule` - Now the command does not fail when checking if SQLPS is loaded into the session (issue #1928). --- CHANGELOG.md | 6 ++++++ source/Public/Import-SqlDscPreferredModule.ps1 | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 114a5acfa..280ad4993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 (tested v21.0.17099). The parameter will be ignored if SQLPS module will be used. +### Fixed + +- `Import-SqlDscPreferredModule` + - Now the command does not fail when checking if SQLPS is loaded into the + session ([issue #1928](https://github.com/dsccommunity/SqlServerDsc/issues/1928)). + ## [16.3.0] - 2023-04-26 ### Remove diff --git a/source/Public/Import-SqlDscPreferredModule.ps1 b/source/Public/Import-SqlDscPreferredModule.ps1 index 0b422f8ad..9339c7722 100644 --- a/source/Public/Import-SqlDscPreferredModule.ps1 +++ b/source/Public/Import-SqlDscPreferredModule.ps1 @@ -96,8 +96,12 @@ function Import-SqlDscPreferredModule { if (-not $Force.IsPresent) { - # Check if the preferred module is already loaded into the session. - $loadedModuleName = (Get-Module -Name $availableModuleName | Select-Object -First 1).Name + <# + Check if the preferred module is already loaded into the session. + If the module name is a path the leaf part must be used, which is + the module name. + #> + $loadedModuleName = (Get-Module -Name (Split-Path -Path $availableModuleName -Leaf) | Select-Object -First 1).Name if ($loadedModuleName) {