Get-AstScriptCommand¶
SYNOPSIS¶
Retrieves the commands used within a specified PowerShell script.
SYNTAX¶
Ast (Default)¶
Get-AstScriptCommand [-Name <String>] -Ast <Ast> [-Recurse] [-IncludeCallOperators]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
Path¶
Get-AstScriptCommand [-Name <String>] -Path <String> [-Recurse] [-IncludeCallOperators]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
Script¶
Get-AstScriptCommand [-Name <String>] -Script <String> [-Recurse] [-IncludeCallOperators]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
DESCRIPTION¶
Analyzes a given PowerShell script and extracts all command invocations. Optionally includes call operators (& and .) in the results. Returns details such as command name, position, and file reference.
EXAMPLES¶
EXAMPLE 1¶
Get-AstScriptCommand -Path "C:\Scripts\example.ps1"
Extracts and lists all commands found in the specified PowerShell script.
EXAMPLE 2¶
Get-AstScriptCommand -Path "C:\Scripts\example.ps1" -IncludeCallOperators
Extracts all commands, including those executed with call operators (& and .).
PARAMETERS¶
-Name¶
The name of the function to search for. Defaults to all functions ('*').
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: *
Accept pipeline input: False
Accept wildcard characters: False
-Path¶
The path to the PowerShell script file to be parsed. Validate using Test-Path
Type: String
Parameter Sets: Path
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
-Script¶
The PowerShell script to be parsed.
Type: String
Parameter Sets: Script
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
-Ast¶
An existing Ast object to search.
Type: Ast
Parameter Sets: Ast
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
-Recurse¶
Search nested functions and script block expressions.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-IncludeCallOperators¶
Include call operators in the results, i.e. & and .
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
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¶
RELATED LINKS¶
https://psmodule.io/Ast/Functions/Scripts/Get-AstScriptCommand/