The PowerShell Language and Analysis Tools

Source Code

Interesting repos and other links for PowerShell:

Installing from Sources

TODO: Instructions on how to get source code, compile, and use it.

The Language

The definitions can be found in the following:

The source for the official documentation is in:

RFC Documents are also in GitHub.


Parsing PowerShell Code

The main classes of interest for analyzing PowerShell code are in the System.Management.Automation namespace.

For example, to tokenize a file/expression:

$tokens = [System.Management.Automation.PSParser]::Tokenize((Get-Content .\script.ps1), [ref]$null)

To get the Abstract Syntax Tree (as well as the requirements):

$ast = [System.Management.Automation.Language.Parser]::ParseInput((Get-Content ShellDebuggin
g.ps1), [ref]$null, [ref]$null)

$ast.scriptRequirements

Then create a custom visitor by extending the AstVisitor or AstVisitor2 class, and use $ast.Visit($myvisitor).

See also:

  1. PowerShell: Tokenization and Abstract Syntax Tree
  2. System.Management.Automation.Language Namespace

results matching ""

    No results matching ""