@@ -40,7 +40,7 @@ function Get-DSCResourceModules {
40
40
}
41
41
}
42
42
}
43
-
43
+
44
44
return $dscModulePsd1List
45
45
}
46
46
@@ -83,7 +83,7 @@ function Add-AstMembers {
83
83
[DscResourcePropertyInfo ]$prop = [DscResourcePropertyInfo ]::new()
84
84
$prop.Name = $property.Name
85
85
$prop.PropertyType = $property.PropertyType.TypeName.Name
86
- $prop.IsMandatory = $isKeyProperty
86
+ $prop.IsMandatory = $isKeyProperty
87
87
$Properties.Add ($prop )
88
88
}
89
89
}
@@ -104,7 +104,7 @@ function FindAndParseResourceDefinitions {
104
104
if (" .psm1" , " .ps1" -notcontains ([System.IO.Path ]::GetExtension($filePath ))) {
105
105
return
106
106
}
107
-
107
+
108
108
" Loading resources from file '$filePath '" | Write-DscTrace - Operation Trace
109
109
# TODO: Ensure embedded instances in properties are working correctly
110
110
[System.Management.Automation.Language.Token []] $tokens = $null
@@ -134,13 +134,13 @@ function FindAndParseResourceDefinitions {
134
134
$DscResourceInfo.Module = $filePath
135
135
$DscResourceInfo.Path = $filePath
136
136
# TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
137
- $DscResourceInfo.ModuleName = [System.IO.Path ]::GetFileNameWithoutExtension($filePath )
137
+ $DscResourceInfo.ModuleName = [System.IO.Path ]::GetFileNameWithoutExtension($filePath )
138
138
$DscResourceInfo.ParentPath = [System.IO.Path ]::GetDirectoryName($filePath )
139
139
$DscResourceInfo.Version = $moduleVersion
140
140
141
141
$DscResourceInfo.Properties = [System.Collections.Generic.List [DscResourcePropertyInfo ]]::new()
142
142
Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
143
-
143
+
144
144
$resourceList.Add ($DscResourceInfo )
145
145
}
146
146
}
@@ -157,7 +157,7 @@ function LoadPowerShellClassResourcesFromModule {
157
157
)
158
158
159
159
" Loading resources from module '$ ( $moduleInfo.Path ) '" | Write-DscTrace - Operation Trace
160
-
160
+
161
161
if ($moduleInfo.RootModule ) {
162
162
if (" .psm1" , " .ps1" -notcontains ([System.IO.Path ]::GetExtension($moduleInfo.RootModule )) -and
163
163
(-not $moduleInfo.NestedModules )) {
@@ -190,8 +190,8 @@ function LoadPowerShellClassResourcesFromModule {
190
190
This function caches the results of the Get-DscResource call to optimize performance.
191
191
192
192
. DESCRIPTION
193
- This function is designed to improve the performance of DSC operations by caching the results of the Get-DscResource call.
194
- By storing the results, subsequent calls to Get-DscResource can retrieve the cached data instead of making a new call each time.
193
+ This function is designed to improve the performance of DSC operations by caching the results of the Get-DscResource call.
194
+ By storing the results, subsequent calls to Get-DscResource can retrieve the cached data instead of making a new call each time.
195
195
This can significantly speed up operations that need to repeatedly access DSC resources.
196
196
197
197
. EXAMPLE
@@ -240,7 +240,7 @@ function Invoke-DscCacheRefresh {
240
240
foreach ($cacheEntry in $dscResourceCacheEntries ) {
241
241
242
242
$cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
243
-
243
+
244
244
if (Test-Path $_.Name ) {
245
245
$file_LastWriteTime = (Get-Item $_.Name ).LastWriteTime
246
246
# Truncate DateTime to seconds
@@ -289,7 +289,7 @@ function Invoke-DscCacheRefresh {
289
289
" Cache file not found '$cacheFilePath '" | Write-DscTrace
290
290
$refreshCache = $true
291
291
}
292
-
292
+
293
293
if ($refreshCache ) {
294
294
' Constructing Get-DscResource cache' | Write-DscTrace
295
295
@@ -306,7 +306,7 @@ function Invoke-DscCacheRefresh {
306
306
$processedModuleNames.Add ($mod.Name , $true )
307
307
308
308
# from several modules with the same name select the one with the highest version
309
- $selectedMod = $modules | Where-Object Name -EQ $mod.Name
309
+ $selectedMod = $modules | Where-Object Name -EQ $mod.Name
310
310
if ($selectedMod.Count -gt 1 ) {
311
311
" Found $ ( $selectedMod.Count ) modules with name '$ ( $mod.Name ) '" | Write-DscTrace - Operation Trace
312
312
$selectedMod = $selectedMod | Sort-Object - Property Version - Descending | Select-Object - First 1
@@ -407,7 +407,7 @@ function Invoke-DscOperation {
407
407
408
408
# workaround: script based resources do not validate Get parameter consistency, so we need to remove any parameters the author chose not to include in Get-TargetResource
409
409
switch ([dscResourceType ]$cachedDscResourceInfo.ImplementationDetail ) {
410
-
410
+
411
411
' ClassBased' {
412
412
try {
413
413
# load powershell class from external module
@@ -424,7 +424,7 @@ function Invoke-DscOperation {
424
424
# handle input objects by converting them to a hash table
425
425
if ($_.Value -is [System.Management.Automation.PSCustomObject ]) {
426
426
$validateProperty = $cachedDscResourceInfo.Properties | Where-Object - Property Name -EQ $_.Name
427
- if ($validateProperty.PropertyType -eq ' PSCredential' ) {
427
+ if ($validateProperty -and $validateProperty .PropertyType -eq ' PSCredential' ) {
428
428
if (-not $_.Value.Username -or -not $_.Value.Password ) {
429
429
" Credential object '$ ( $_.Name ) ' requires both 'username' and 'password' properties" | Write-DscTrace - Operation Error
430
430
exit 1
@@ -453,7 +453,7 @@ function Invoke-DscOperation {
453
453
}
454
454
' Test' {
455
455
$Result = $dscResourceInstance.Test ()
456
- $addToActualState.properties = [psobject ]@ {' InDesiredState' = $Result }
456
+ $addToActualState.properties = [psobject ]@ {' InDesiredState' = $Result }
457
457
}
458
458
' Export' {
459
459
$t = $dscResourceInstance.GetType ()
@@ -464,7 +464,7 @@ function Invoke-DscOperation {
464
464
break
465
465
}
466
466
}
467
-
467
+
468
468
if ($null -eq $method ) {
469
469
" Export method not implemented by resource '$ ( $DesiredState.Type ) '" | Write-DscTrace - Operation Error
470
470
exit 1
@@ -481,7 +481,7 @@ function Invoke-DscOperation {
481
481
}
482
482
}
483
483
catch {
484
-
484
+
485
485
' Exception: ' + $_.Exception.Message | Write-DscTrace - Operation Error
486
486
exit 1
487
487
}
0 commit comments