Run PSScriptAnalyzer over a repo
Documentation: Microsoft Learn
Scan scripts and modules recursively with Invoke-ScriptAnalyzer, then export rule names, severity, and line numbers to CSV for review.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Invoke-ScriptAnalyzer -Path . -Recurse | Export-Csv .\PSScriptAnalyzer.csv -NoTypeInformation- Stage 1Invoke-ScriptAnalyzer
-Path -Recurse - Stage 2Export-Csv
-NoTypeInformation
How it works
Invoke-ScriptAnalyzer walks the current directory recursively, evaluating every script and module file against the installed rule set, and Export-Csv writes the diagnostics out with rule name, severity, and line number so the results can be triaged.
Adapting it
Add -Severity Error to the call so a build step fails only on genuine problems while warnings remain advisory, which is what makes the check tolerable to a team that did not ask for it.
Requirements
PSScriptAnalyzer module installed.
If the result is unexpected
PSScriptAnalyzer reports no findings while expected files are unchecked.
The path, recursion option, excluded rules or missing module can change what is analyzed.
- Confirm the analyzer version and enumerate the files covered by the invocation.
Validate the result
A file with a known rule violation is included and produces the expected diagnostic.
Keep the check reliable
Pin the rule configuration and record the scanned paths in CI output.