PowerShell Genie

PSScriptAnalyzer module: setup and commands

Module 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Run Invoke-ScriptAnalyzer with explicit rules and settings, separate style findings from correctness issues and suppress rules only with a reason.

Getting it

Install-PSResource -Name PSScriptAnalyzer from the PowerShell Gallery. The PowerShell editor extensions bundle it, so a copy may already be present.

Examples

1PS> Invoke-ScriptAnalyzer -Path . -Recurse
Show reference output
1 RuleName Severity Line Message
2 -------- -------- ---- -------
3 PSAvoidUsingWriteHost Warning 14 File output should use a data stream instead of Write-Host.
1PS> Get-ScriptAnalyzerRule
Show reference output
1 RuleName Severity
2 -------- --------
3 PSAvoidUsingCmdletAliases Warning
4 PSUseApprovedVerbs Warning

What it is for

Run it before review so the mechanical findings never reach a human reader. It also gives a team something concrete to standardize on, since a settings file can select or suppress individual rules.

Typical tasks

  • Scan a repository for rule violations
  • Enforce approved verbs and naming
  • Catch plain text password parameters
  • Fail a build on Error severity findings
  • Reformat files to a shared style
  • Suppress a rule with a written justification

Check the installed version

1PS> Get-Module -ListAvailable PSScriptAnalyzer | Select-Object Name, Version, Path
2PS> Get-Command -Module PSScriptAnalyzer

Compare the module path and version with the session used by your scheduled task or automation account. Run it before review so the mechanical findings never reach a human reader. It also gives a team something concrete to standardize on, since a settings file can select or suppress individual rules.

Primary documentation

PSScriptAnalyzer documentation

Continue
Genie guidePSScriptAnalyzer module: setup and commands

Run Invoke-ScriptAnalyzer with explicit rules and settings, separate style findings from correctness issues and suppress rules only with a reason.