File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ class PSClassResource {
118118 New-Item - Path $modulePath - ItemType File - Value $module - Force | Out-Null
119119 }
120120
121- $env: PSModulePath = $windowsPowerShellPath + [System.IO.Path ]::PathSeparator + $env: PSModulePath
121+ $env: PSModulePath = $windowsPowerShellPath + [System.IO.Path ]::PathSeparator + $env: PSModulePath + [ System.IO.Path ]::PathSeparator
122122 }
123123
124124 AfterAll {
Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ function Invoke-DscCacheRefresh {
6060 $namedModules = [System.Collections.Generic.List [Object ]]::new()
6161 $cacheFilePath = Join-Path $env: LocalAppData " dsc\WindowsPSAdapterCache.json"
6262
63+ # Reset PSModulePath to not contain empty entries
64+ Set-ValidPSModulePath
65+
6366 if (Test-Path $cacheFilePath ) {
6467 " Reading from Get-DscResource cache file $cacheFilePath " | Write-DscTrace
6568
@@ -244,10 +247,10 @@ function Invoke-DscCacheRefresh {
244247 }
245248
246249 $dscResourceCacheEntries.Add ([dscResourceCacheEntry ]@ {
247- Type = " $moduleName /$ ( $dscResource.Name ) "
248- DscResourceInfo = $DscResourceInfo
249- LastWriteTimes = $lastWriteTimes
250- })
250+ Type = " $moduleName /$ ( $dscResource.Name ) "
251+ DscResourceInfo = $DscResourceInfo
252+ LastWriteTimes = $lastWriteTimes
253+ })
251254 }
252255
253256 if ($namedModules.Count -gt 0 ) {
@@ -701,6 +704,19 @@ function GetClassBasedCapabilities {
701704 }
702705}
703706
707+ function Set-ValidPSModulePath {
708+ [CmdletBinding ()]
709+ param ()
710+
711+ end {
712+ if (($env: PSModulePath -split [System.IO.Path ]::PathSeparator) -contains ' ' ) {
713+ " Removing empty entry from PSModulePath: '$env: PSModulePath '" | Write-DscTrace - Operation Debug
714+ $env: PSModulePath = ($env: PSModulePath -split [System.IO.Path ]::PathSeparator | Where-Object { $_ -ne ' ' }) -join [System.IO.Path ]::PathSeparator
715+ }
716+ }
717+ }
718+
719+
704720# cached resource
705721class dscResourceCacheEntry {
706722 [string ] $Type
You can’t perform that action at this time.
0 commit comments