PowerShell Genie

Run PSScriptAnalyzer over a repo

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

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

1PS> Invoke-ScriptAnalyzer -Path . -Recurse | Export-Csv .\PSScriptAnalyzer.csv -NoTypeInformation

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 (No pipeline output. The selected objects were written to the CSV file.)
    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
    1. Stage 1Invoke-ScriptAnalyzer-Path -Recurse
    2. 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.

      1. 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.

      Primary documentation

      Export-Csv reference

      Continue
      Genie guideRun PSScriptAnalyzer over a repo

      Scan scripts and modules recursively with Invoke-ScriptAnalyzer, then export rule names, severity, and line numbers to CSV for review.