PowerShell / PowerShell/PSScriptAnalyzer
Settings param cannot be set to $_ inside of a foreach-object loop
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
When the value of the -Settings parameter is set to $_ inside of a foreach-object loop, PSScriptAnalyzer is unable to find the settings file.
Steps to reproduce:
Create a file that violates a rule that is only checked if a particular setting is triggered.
IE:
if ($true)
{
Write-Output 'Something'
}
This code will throw errors if -Settings is set to CodeFormattingStroustrup but not if -Settings it is omitted.
The following command returns warnings.
invoke-scriptanalyzer -path C:\files\ax.ps1 -Settings 'CodeFormattingStroustrup'
But this one does not.
'CodeFormattingStroustrup' | % { invoke-scriptanalyzer -path C:\files\ax.ps1 -Settings $_ }
Using -Verbose on the non-working example shows that PSScriptAnalyzer cannot find a settings file.
This occurs on version 1.15.0 of PSScriptAnalyzer.
Screenshot

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Invoke-ScriptAnalyzer entry point and reproduce the difference between a direct -Settings value and the foreach-object form using -Verbose. Trace how the settings value is resolved in both invocations; done means the piped $_ form locates CodeFormattingStroustrup and reports the same warnings as the direct command.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100