Skip to content

Get‑ClassResourceAst

viscalyxbot edited this page Sep 16, 2025 · 1 revision

SYNOPSIS

Gets DSC class resource definitions from a PowerShell script file using AST parsing.

SYNTAX

String (Default)

Get-ClassResourceAst -Path <String[]> [-ClassName <String>] 
 [<CommonParameters>]

FileInfo

Get-ClassResourceAst -ScriptFile <FileInfo[]> [-ClassName <String>] 
 [<CommonParameters>]

DESCRIPTION

The Get-ClassResourceAst function parses a PowerShell script file and extracts DSC class resource definitions using Abstract Syntax Tree (AST) parsing. It filters for classes that have the [DscResource()] attribute. It can return all DSC class resources in the file or filter for a specific class by name.

EXAMPLES

EXAMPLE 1

Get-ClassResourceAst -Path 'C:\Scripts\MyDscResources.ps1'

Returns all DSC class resource definitions found in the specified script file.

EXAMPLE 2

Get-ClassResourceAst -Path 'C:\Scripts\MyDscResources.ps1' -ClassName 'MyDscResource'

Returns only the 'MyDscResource' DSC class resource definition from the specified script file.

EXAMPLE 3

'C:\Scripts\Resource1.ps1', 'C:\Scripts\Resource2.ps1' | Get-ClassResourceAst

Returns all DSC class resource definitions found in the specified script files using pipeline input.

EXAMPLE 4

Get-ChildItem -Path 'C:\Scripts\*.ps1' | Get-ClassResourceAst -ClassName 'MyDscResource'

Returns 'MyDscResource' DSC class resource definitions from all PowerShell script files in the specified directory.

PARAMETERS

-ClassName

Optional parameter to filter for a specific DSC class resource by name. If not provided, all DSC class resources in the script file are returned.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Path

The path(s) to the PowerShell script file(s) to parse. Accepts pipeline input from strings (file paths).

Type: String[]
Parameter Sets: String
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-ScriptFile

FileInfo object(s) representing the PowerShell script file(s) to parse. Accepts pipeline input from Get-ChildItem and other commands that return FileInfo objects.

Type: FileInfo[]
Parameter Sets: FileInfo
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

System.String[]

You can pipe file paths as strings to this function.

System.IO.FileInfo[]

You can pipe FileInfo objects to this function.

OUTPUTS

System.Collections.Generic.IEnumerable`1System.Management.Automation.Language.Ast

Returns a collection of AST nodes (items are TypeDefinitionAst) representing

the DSC class resource definitions found in the script file. Returns an empty collection

if no DSC class resources are found or when filtering for a non-existent class name.

NOTES

RELATED LINKS

Clone this wiki locally