Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.36 KB

File metadata and controls

54 lines (36 loc) · 1.36 KB

Ast

Ast is a PowerShell module for using the PowerShell abstract syntax tree (AST) to analyze PowerShell code. It provides commands to extract functions, commands, aliases, comments, and script structure from a file, a string of script content, or an existing AST object.

Installation

Install the module from the PowerShell Gallery:

Install-PSResource -Name Ast
Import-Module -Name Ast

Usage

The commands accept a file path (-Path) or inline script content (-Script), and default to matching everything so you can narrow the results with -Name.

Example: List the functions defined in a script

Get-AstFunction -Path ./MyScript.ps1
Get-AstFunctionName -Path ./MyScript.ps1

Example: Find the commands invoked by a script

Get-AstCommand -Path ./MyScript.ps1
Get-AstCommand -Script "Get-Process; Write-Host 'Hello'"

Example: Inspect a single function by name

Get-AstFunction -Path ./MyScript.ps1 -Name 'Test-Me'

Documentation

Documentation is published at psmodule.io/Ast.

Use PowerShell help and command discovery for module details:

Get-Command -Module Ast
Get-Help -Name Get-AstFunction -Examples

Related tools