Linting in PowerShell

Continuing the theme of C++ flavoured tools I miss, lint is another essential that doesn’t appear to exist in the PowerShell world. Until I discovered ScriptAnalyzer which, it seems, can do pretty much the same job for .ps1 files. Here I wrote a simple loop to check all files in the same directory.


# Install-Module PSScriptAnalyzer 

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

Get-ChildItem -Path $here -Filter *.ps1 -Recurse | ForEach-Object {

    Invoke-ScriptAnalyzer -Path $_.FullName -IncludeDefaultRules -OutVariable Failures

	If ($Failures.Count -gt 0) {
		Write-Output "$_.FullName - $($Failures.Count) rule failures"
	}
}