Skip to content

Get-AstFunctionName

SYNOPSIS

Retrieves the names of functions from an abstract syntax tree (Ast) in a PowerShell script.

SYNTAX

Path

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

Script

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

ALIASES

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

DESCRIPTION

Parses a PowerShell script file or script content to extract function names using an abstract syntax tree (Ast). The function supports searching by name, parsing from a file path, or directly from a script string. It can also search within nested functions and script block expressions when the -Recurse switch is used.

EXAMPLES

EXAMPLE 1

Get-AstFunctionName -Path "C:\Scripts\example.ps1"

Output:

Get-Data
Set-Configuration

Extracts function names from the specified PowerShell script file.

EXAMPLE 2

Get-AstFunctionName -Script "function Test-Function { param($x) Write-Host $x }"

Output:

Test-Function

Extracts function names from the given script string.

EXAMPLE 3

Get-AstFunctionName -Path "C:\Scripts\example.ps1" -Recurse

Output:

Get-Data
Set-Configuration
Helper-Function

Extracts function names from the specified script file, including nested functions.

PARAMETERS

-Name

The name of the command to search for. Defaults to all commands ('*').

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 }}

OUTPUTS

System.String

The names of functions found in the PowerShell script.

{{ Fill in the Description }}

NOTES

The name of each function found in the PowerShell script.