Get-AstScript¶
SYNOPSIS¶
Parses a PowerShell script or script file and returns its abstract syntax tree (Ast).
SYNTAX¶
Path¶
Get-AstScript -Path <string> [<CommonParameters>]
Script¶
Get-AstScript -Script <string> [<CommonParameters>]
ALIASES¶
This cmdlet has the following aliases, {{Insert list of aliases}}
DESCRIPTION¶
The Get-AstScript function parses a PowerShell script or script file and returns its abstract syntax tree (Ast), along with tokens and errors encountered during parsing. This function can be used to analyze the structure of a script by specifying either the script content directly or the path to a script file.
EXAMPLES¶
EXAMPLE 1¶
Get-AstScript -Path "C:\Scripts\example.ps1"
Output:
Ast : [System.Management.Automation.Language.ScriptBlockAst]
Tokens : {Token1, Token2, ...}
Errors : {Error1, Error2, ...}
Parses the PowerShell script located at "C:\Scripts\example.ps1" and returns its Ast, tokens, and any parsing errors.
EXAMPLE 2¶
Get-AstScript -Script "Write-Host 'Hello World'"
Output:
Ast : [System.Management.Automation.Language.ScriptBlockAst]
Tokens : {Token1, Token2, ...}
Errors : {}
Parses the provided PowerShell script string and returns its Ast, tokens, and any parsing errors.
PARAMETERS¶
-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: ''
-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¶
PSCustomObject¶
{{ Fill in the Description }}
System.Management.Automation.Language.ScriptBlockAst¶
{{ Fill in the Description }}
NOTES¶
The returned custom object contains the following properties:
- Ast
- [System.Management.Automation.Language.ScriptBlockAst].
The abstract syntax tree (Ast) of the parsed script.
- Tokens
- [System.Management.Automation.Language.Token[]].
The tokens generated during parsing.
- Errors
- [System.Management.Automation.Language.ParseError[]].
Any parsing errors encountered.