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:
- Windows PowerShell Language Specification Version 2.0
- Windows PowerShell Language Specification Version 3.0
- Windows PowerShell 4.0 and Other Quick Reference Guides: Not really a specification (far away from it), but it contains some useful information and links.
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: