@@ -127,7 +127,6 @@ function Invoke-DscCacheRefresh {
127
127
$diff = $hs_cache
128
128
129
129
" PSModulePath diff '$diff '" | Write-DscTrace
130
-
131
130
if ($diff.Count -gt 0 ) {
132
131
$refreshCache = $true
133
132
}
@@ -154,10 +153,17 @@ function Invoke-DscCacheRefresh {
154
153
}
155
154
$DscResources = [System.Collections.Generic.List [Object ]]::new()
156
155
$Modules = [System.Collections.Generic.List [Object ]]::new()
156
+ $filteredResources = @ ()
157
157
foreach ($m in $module ) {
158
158
$DscResources += Get-DscResource - Module $m
159
159
$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 ) }
160
163
}
164
+
165
+ # Exclude the one module that was passed in as a parameter
166
+ $existingDscResourceCacheEntries = $cache.ResourceCache | Where-Object - Property Type -NotIn $filteredResources
161
167
}
162
168
elseif (' PSDesiredStateConfiguration' -eq $module -and $PSVersionTable.PSVersion.Major -le 5 ) {
163
169
# the resources in Windows should only load in Windows PowerShell
@@ -248,6 +254,13 @@ function Invoke-DscCacheRefresh {
248
254
$cache.PSModulePaths = $m.FullName
249
255
$cache.CacheSchemaVersion = $script :CurrentCacheSchemaVersion
250
256
257
+ if ($existingDscResourceCacheEntries ) {
258
+ $cache.ResourceCache += $existingDscResourceCacheEntries
259
+
260
+ # Make sure all resource cache entries are returned
261
+ $dscResourceCacheEntries = $cache.ResourceCache
262
+ }
263
+
251
264
# save cache for future use
252
265
# TODO: replace this with a high-performance serializer
253
266
" Saving Get-DscResource cache to '$cacheFilePath '" | Write-DscTrace
0 commit comments