A Crash Course in Writing Your Own PSScriptAnalyzer Rules
summary
Shows how to extend PSScriptAnalyzer by writing PowerShell rules that parse the abstract syntax tree and inspect parameter AST objects to detect concrete violations. Builds a rule that flags multiple parameters with value from pipeline in the same parameter set, runs it against a sample file, and finds two real violations. Outputs diagnostic record objects so results integrate with PSScriptAnalyzer formatting. Solution works end to end but has edge cases (quoting, nested scopes, unit tests) and needs refinement.
AI-written summary · about
chapters (21)
- 0:00Introduction
- 8:00Importing Modules
- 9:15Simple Function
- 11:25Different AST Objects
- 12:48Parameter AST
- 13:32Parameter Parameter
- 13:58Parameter Name
- 14:53Variable Path
- 16:42Attributes
- 19:50Warnings
- 20:33Detecting Violations
- 21:30Command with Binding
- 22:27Parameters AST
- 23:39Parameter Attributes
- 29:31Parameter Set Name
- 30:04Custom Object
- 31:15PSScriptAnalyzer Role
- 33:37Invoke Custom Role
- 40:10Parameter Sets
- 41:41Running the Rule
- 43:40Ideas for Improvement
related talks
46mPSScriptAnalyzer (PSSA) VS-code integration & customization Compatibility Analysis
47mThe Human Side of PowerShell Scripting
01h 37mMore Game Breaking PowerShell
50mPractical Advanced Static Analysis
45mGitHub Actions for Fun and Profit
30mPokekYoke Mistake-Proofing your PowerShell scripts and functions
52mPowerShell Module Design Rules (and When to Bend Them)
01h 14mCreating a PowerShell Editor
