Skip to content

Invoke-ScriptAnalyzer: An item with the same key has already been added. What is the proper syntax? #1511

Closed
@RylandDeGregory

Description

@RylandDeGregory

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

Screen Shot 2020-05-22 at 4 33 03 PM

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions