Skip to content

Get-AstFunction

SYNOPSIS

Retrieves function definitions from a PowerShell script or Ast.

SYNTAX

Ast (Default)

Get-AstFunction -Ast <Ast> [-Name <string>] [-Recurse] [<CommonParameters>]

Path

Get-AstFunction -Path <string> [-Name <string>] [-Recurse] [<CommonParameters>]

Script

Get-AstFunction -Script <string> [-Name <string>] [-Recurse] [<CommonParameters>]

ALIASES

This cmdlet has the following aliases, {{Insert list of aliases}}

DESCRIPTION

This function extracts function definitions from a given PowerShell script file, script content, or an existing Ast (Abstract Syntax Tree) object. It supports searching by function name and can optionally search within nested functions and script block expressions.

EXAMPLES

EXAMPLE 1

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

Output:

Ast    : {FunctionDefinitionAst, FunctionDefinitionAst}
Tokens : {...}
Errors : {}

Retrieves function definitions from the specified script file.

EXAMPLE 2

Get-AstFunction -Script "$scriptContent"

Output:

Ast    : {FunctionDefinitionAst}
Tokens : {...}
Errors : {}

Parses and retrieves function definitions from the provided script content.

EXAMPLE 3

$ast = Get-AstScript -Path "C:\Scripts\MyScript.ps1" | Select-Object -ExpandProperty Ast Get-AstFunction -Ast $ast

Output:

Ast    : {FunctionDefinitionAst}
Tokens : {...}
Errors : {}

Extracts function definitions from an existing Ast object.

PARAMETERS

-Ast

An existing Ast object to search.

Type: System.Management.Automation.Language.Ast
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Ast
  Position: Named
  IsRequired: true
  ValueFromPipeline: true
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Name

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

Type: System.String
DefaultValue: '*'
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Path

The path to the PowerShell script file to be parsed. Validate using Test-Path

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Path
  Position: Named
  IsRequired: true
  ValueFromPipeline: true
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Recurse

Search nested functions and script block expressions.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Script

The PowerShell script to be parsed.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Script
  Position: Named
  IsRequired: true
  ValueFromPipeline: true
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

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

INPUTS

System.String

{{ Fill in the Description }}

System.Management.Automation.Language.Ast

{{ Fill in the Description }}

OUTPUTS

PSCustomObject

{{ Fill in the Description }}

NOTES

Contains Ast objects, tokenized script content, and parsing errors if any.