@@ -226,6 +226,8 @@ function Invoke-DscCacheRefresh {
226
226
if ($null -ne $properties ) {
227
227
$DscResourceInfo.Properties = $properties
228
228
}
229
+
230
+ $dscResourceInfo.Capabilities = GetClassBasedCapabilities - filePath $dscResource.Path - className $dscResource.Name
229
231
}
230
232
231
233
# fill in resource files (and their last-write-times) that will be used for up-do-date checks
@@ -632,6 +634,64 @@ function GetClassBasedProperties {
632
634
}
633
635
}
634
636
637
+ function GetClassBasedCapabilities {
638
+ param (
639
+ [Parameter (Mandatory = $true )]
640
+ [string ] $filePath ,
641
+
642
+ [Parameter (Mandatory = $true )]
643
+ [string ] $className
644
+ )
645
+
646
+ if (" .psd1" -notcontains ([System.IO.Path ]::GetExtension($filePath ))) {
647
+ return @ (' get' , ' set' , ' test' )
648
+ }
649
+
650
+ $module = $filePath.Replace (' .psd1' , ' .psm1' )
651
+
652
+ if (Test-Path $module - ErrorAction Ignore) {
653
+ [System.Management.Automation.Language.Token []] $tokens = $null
654
+ [System.Management.Automation.Language.ParseError []] $errors = $null
655
+ $ast = [System.Management.Automation.Language.Parser ]::ParseFile($module , [ref ]$tokens , [ref ]$errors )
656
+ foreach ($e in $errors ) {
657
+ $e | Out-String | Write-DscTrace - Operation Error
658
+ }
659
+
660
+ $typeDefinitions = $ast.FindAll (
661
+ {
662
+ $typeAst = $args [0 ] -as [System.Management.Automation.Language.TypeDefinitionAst ]
663
+ return $null -ne $typeAst ;
664
+ },
665
+ $false );
666
+
667
+
668
+ $capabilities = [System.Collections.Generic.List [string []]]::new()
669
+ $availableMethods = @ (' get' , ' set' , ' setHandlesExist' , ' whatIf' , ' test' , ' delete' , ' export' )
670
+ foreach ($typeDefinitionAst in $typeDefinitions ) {
671
+ foreach ($a in $typeDefinitionAst.Attributes ) {
672
+ if ($a.TypeName.Name -eq ' DscResource' -and $a.Parent.Name -eq $className ) {
673
+ $methods = $typeDefinitionAst.Members | Where-Object { $_ -is [System.Management.Automation.Language.FunctionMemberAst ] -and $_.Name -in $availableMethods }
674
+
675
+ foreach ($method in $methods.Name ) {
676
+ # We go through each method to properly case handle the method names.
677
+ switch ($method ) {
678
+ ' Get' { $capabilities.Add (' get' ) }
679
+ ' Set' { $capabilities.Add (' set' ) }
680
+ ' Test' { $capabilities.Add (' test' ) }
681
+ ' WhatIf' { $capabilities.Add (' whatIf' ) }
682
+ ' SetHandlesExist' { $capabilities.Add (' setHandlesExist' ) }
683
+ ' Delete' { $capabilities.Add (' delete' ) }
684
+ ' Export' { $capabilities.Add (' export' ) }
685
+ }
686
+ }
687
+ }
688
+ }
689
+ }
690
+
691
+ return $capabilities
692
+ }
693
+ }
694
+
635
695
# cached resource
636
696
class dscResourceCacheEntry {
637
697
[string ] $Type
@@ -681,4 +741,5 @@ class DscResourceInfo {
681
741
[string ] $ImplementedAs
682
742
[string ] $CompanyName
683
743
[psobject []] $Properties
684
- }
744
+ [string []] $Capabilities
745
+ }
0 commit comments