Skip to content

Commit 9075bd4

Browse files
committed
Fix resourceCache to return proper modules when PS modules are installed during run
1 parent 4407d22 commit 9075bd4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ function Invoke-DscCacheRefresh {
127127
$diff = $hs_cache
128128

129129
"PSModulePath diff '$diff'" | Write-DscTrace
130-
131130
if ($diff.Count -gt 0) {
132131
$refreshCache = $true
133132
}
@@ -154,10 +153,17 @@ function Invoke-DscCacheRefresh {
154153
}
155154
$DscResources = [System.Collections.Generic.List[Object]]::new()
156155
$Modules = [System.Collections.Generic.List[Object]]::new()
156+
$filteredResources = @()
157157
foreach ($m in $module) {
158158
$DscResources += Get-DscResource -Module $m
159159
$Modules += Get-Module -Name $m -ListAvailable
160+
161+
# Grab all DSC resources to filter out of the cache
162+
$filteredResources += $dscResources | Where-Object -Property ModuleName -NE $null | ForEach-Object { [System.String]::Concat($_.ModuleName, '/', $_.Name) }
160163
}
164+
165+
# Exclude the one module that was passed in as a parameter
166+
$existingDscResourceCacheEntries = $cache.ResourceCache | Where-Object -Property Type -NotIn $filteredResources
161167
}
162168
elseif ('PSDesiredStateConfiguration' -eq $module -and $PSVersionTable.PSVersion.Major -le 5 ) {
163169
# the resources in Windows should only load in Windows PowerShell
@@ -248,6 +254,13 @@ function Invoke-DscCacheRefresh {
248254
$cache.PSModulePaths = $m.FullName
249255
$cache.CacheSchemaVersion = $script:CurrentCacheSchemaVersion
250256

257+
if ($existingDscResourceCacheEntries) {
258+
$cache.ResourceCache += $existingDscResourceCacheEntries
259+
260+
# Make sure all resource cache entries are returned
261+
$dscResourceCacheEntries = $cache.ResourceCache
262+
}
263+
251264
# save cache for future use
252265
# TODO: replace this with a high-performance serializer
253266
"Saving Get-DscResource cache to '$cacheFilePath'" | Write-DscTrace

0 commit comments

Comments
 (0)