Closed
Description
I seem to be receiving a rule-less error whenever running PSScriptAnalyzer with default settings against a PowerShell script containing the following code block.
Environment
MacOS 10.15.4
PowerShell 7 LTS for MacOS
PSScriptAnalyzer 1.19.0
Code
$result = Invoke-Command -ComputerName $Computername -Credential $RemotingCred -Authentication Negotiate -ScriptBlock {
$output=@()
foreach ($item in $list) {
$out = [PSCustomObject]@{
Property1 = $item.Property1
Property2 = $item.Property2
}
$output += $out
}
return $output
}
Command
Invoke-ScriptAnalyzer -path ./test.ps1
Expected Output
none
Actual Output
Invoke-ScriptAnalyzer: An item with the same key has already been added. Key: output
Question
What is the proper PowerShell syntax to prevent this error from generating? Or, which Rule can I ignore to suppress it? The code executes fine, just for the record :)
Thanks!