diff --git a/powershell-adapter/Tests/win_powershellgroup.tests.ps1 b/powershell-adapter/Tests/win_powershellgroup.tests.ps1 index 88f991697..f5c505478 100644 --- a/powershell-adapter/Tests/win_powershellgroup.tests.ps1 +++ b/powershell-adapter/Tests/win_powershellgroup.tests.ps1 @@ -118,7 +118,7 @@ class PSClassResource { New-Item -Path $modulePath -ItemType File -Value $module -Force | Out-Null } - $env:PSModulePath = $windowsPowerShellPath + [System.IO.Path]::PathSeparator + $env:PSModulePath + $env:PSModulePath = $windowsPowerShellPath + [System.IO.Path]::PathSeparator + $env:PSModulePath + [System.IO.Path]::PathSeparator } AfterAll { diff --git a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 index 47ea29bee..c206d89d9 100644 --- a/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 +++ b/powershell-adapter/psDscAdapter/win_psDscAdapter.psm1 @@ -60,6 +60,9 @@ function Invoke-DscCacheRefresh { $namedModules = [System.Collections.Generic.List[Object]]::new() $cacheFilePath = Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json" + # Repair PSModulePath to not contain empty entries + Repair-ValidPSModulePath + if (Test-Path $cacheFilePath) { "Reading from Get-DscResource cache file $cacheFilePath" | Write-DscTrace @@ -701,6 +704,19 @@ function GetClassBasedCapabilities { } } +function Repair-ValidPSModulePath { + [CmdletBinding()] + param() + + end { + if (($env:PSModulePath -split [System.IO.Path]::PathSeparator) -contains '') { + "Removing empty entry from PSModulePath: '$env:PSModulePath'" | Write-DscTrace -Operation Debug + $env:PSModulePath = [String]::Join([System.IO.Path]::PathSeparator, ($env:PSModulePath.Split([System.IO.Path]::PathSeparator, [System.StringSplitOptions]::RemoveEmptyEntries))).TrimEnd([System.IO.Path]::PathSeparator) + } + } +} + + # cached resource class dscResourceCacheEntry { [string] $Type