Skip to content

Get-FunctionAST

SYNOPSIS

Retrieves the abstract syntax tree (AST) of function definitions from a PowerShell script.

SYNTAX

Get-FunctionAST [[-Name] <String>] [-Path] <String> [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

Parses a specified PowerShell script file and extracts function definitions matching the given name. By default, it returns all function definitions if no specific name is provided.

EXAMPLES

EXAMPLE 1

Get-FunctionAST -Path "C:\Scripts\MyScript.ps1"

Retrieves all function definitions from "MyScript.ps1".

EXAMPLE 2

Get-FunctionAST -Name "Get-Data" -Path "C:\Scripts\MyScript.ps1"

Retrieves only the function definition named "Get-Data" from "MyScript.ps1".

PARAMETERS

-Name

The name of the function to search for. Defaults to all functions ('*').

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: *
Accept pipeline input: False
Accept wildcard characters: False

-Path

The path to the PowerShell script file to be parsed.

Type: String
Parameter Sets: (All)
Aliases:

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

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
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

OUTPUTS

NOTES

https://psmodule.io/AST/Functions/Core/Get-FunctionAST/