1
1
# Copyright (c) Microsoft Corporation.
2
2
# Licensed under the MIT License.
3
3
4
- $script :CurrentCacheSchemaVersion = 2
4
+ $script :CurrentCacheSchemaVersion = 3
5
5
6
6
function Write-DscTrace {
7
7
param (
@@ -60,7 +60,7 @@ function Add-AstMembers {
60
60
61
61
foreach ($member in $TypeAst.Members ) {
62
62
$property = $member -as [System.Management.Automation.Language.PropertyMemberAst ]
63
- if (($property -eq $null ) -or ($property.IsStatic )) {
63
+ if (($null -eq $property ) -or ($property.IsStatic )) {
64
64
continue ;
65
65
}
66
66
$skipProperty = $true
@@ -117,7 +117,7 @@ function FindAndParseResourceDefinitions {
117
117
$typeDefinitions = $ast.FindAll (
118
118
{
119
119
$typeAst = $args [0 ] -as [System.Management.Automation.Language.TypeDefinitionAst ]
120
- return $typeAst -ne $null ;
120
+ return $null -ne $typeAst ;
121
121
},
122
122
$false );
123
123
@@ -139,6 +139,7 @@ function FindAndParseResourceDefinitions {
139
139
$DscResourceInfo.Version = $moduleVersion
140
140
141
141
$DscResourceInfo.Properties = [System.Collections.Generic.List [DscResourcePropertyInfo ]]::new()
142
+ $DscResourceInfo.Capabilities = GetClassBasedCapabilities $typeDefinitionAst.Members
142
143
Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
143
144
144
145
$resourceList.Add ($DscResourceInfo )
@@ -325,7 +326,7 @@ function Invoke-DscCacheRefresh {
325
326
326
327
# fill in resource files (and their last-write-times) that will be used for up-do-date checks
327
328
$lastWriteTimes = @ {}
328
- Get-ChildItem - Recurse - File - Path $dscResource.ParentPath - Include " *.ps1" , " *.psd1" , " *.psm1" , " *.mof" - ea Ignore | % {
329
+ Get-ChildItem - Recurse - File - Path $dscResource.ParentPath - Include " *.ps1" , " *.psd1" , " *.psm1" , " *.mof" - ea Ignore | ForEach-Object {
329
330
$lastWriteTimes.Add ($_.FullName , $_.LastWriteTime )
330
331
}
331
332
@@ -338,7 +339,7 @@ function Invoke-DscCacheRefresh {
338
339
339
340
[dscResourceCache ]$cache = [dscResourceCache ]::new()
340
341
$cache.ResourceCache = $dscResourceCacheEntries
341
- $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | % { Get-ChildItem - Directory - Path $_ - Depth 1 - ea SilentlyContinue }
342
+ $m = $env: PSModulePath -split [IO.Path ]::PathSeparator | ForEach-Object { Get-ChildItem - Directory - Path $_ - Depth 1 - ea SilentlyContinue }
342
343
$cache.PSModulePaths = $m.FullName
343
344
$cache.CacheSchemaVersion = $script :CurrentCacheSchemaVersion
344
345
@@ -529,6 +530,28 @@ function GetTypeInstanceFromModule {
529
530
return $instance
530
531
}
531
532
533
+ function GetClassBasedCapabilities ($functionMemberAst ) {
534
+ $capabilities = [System.Collections.Generic.List [string []]]::new()
535
+ # These are the methods that we can potentially expect in a class-based DSC resource.
536
+ $availableMethods = @ (' get' , ' set' , ' setHandlesExist' , ' whatIf' , ' test' , ' delete' , ' export' )
537
+ $methods = $functionMemberAst | Where-Object { $_ -is [System.Management.Automation.Language.FunctionMemberAst ] -and $_.Name -in $availableMethods }
538
+
539
+ foreach ($method in $methods.Name ) {
540
+ # We go through each method to properly case handle the method names.
541
+ switch ($method ) {
542
+ ' Get' { $capabilities.Add (' get' ) }
543
+ ' Set' { $capabilities.Add (' set' ) }
544
+ ' Test' { $capabilities.Add (' test' ) }
545
+ ' WhatIf' { $capabilities.Add (' whatIf' ) }
546
+ ' SetHandlesExist' { $capabilities.Add (' setHandlesExist' ) }
547
+ ' Delete' { $capabilities.Add (' delete' ) }
548
+ ' Export' { $capabilities.Add (' export' ) }
549
+ }
550
+ }
551
+
552
+ return ($capabilities | Select-Object - Unique)
553
+ }
554
+
532
555
# cached resource
533
556
class dscResourceCacheEntry {
534
557
[string ] $Type
@@ -578,4 +601,5 @@ class DscResourceInfo {
578
601
[string ] $ImplementedAs
579
602
[string ] $CompanyName
580
603
[System.Collections.Generic.List [DscResourcePropertyInfo ]] $Properties
604
+ [string []] $Capabilities
581
605
}
0 commit comments