Custom rules may be used with the CustomRulePath parameter. If the two rules were saved in a Rules.psm1 file, they can be used as follows:
$script = @'
function Get-CurrentProcess {
[CmdletBinding()]
param ( )
begin { }
process { }
end {
#
# Get the current process
#
Get-Process -Id $PID
}
}
'@
Invoke-ScriptAnalyzer -ScriptDefinition $script -CustomRulePath .Rules.psm1
The script analyzer will show each triggered rule, as follows:
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidEmptyComments Information 9 Empty comment.
PSAvoidEmptyComments Information 11 Empty comment.
PSAvoidEmptyNamedBlocks Warning 5 Empty Begin block.
PSAvoidEmptyNamedBlocks Warning 6 Empty Process block.
The script analyzer also allows custom rules to be defined by using a configuration file. The configuration file may be either explicitly or implicitly referenced, as described in the script analyzer's documentation (https://github.com/PowerShell/PSScriptAnalyzer).
VS Code allows a settings path to be globally defined (across any PowerShell project) by defining a value for powershell.scriptAnalysis.settingsPath.