Invoke-ScriptAnalyzer: An item with the same key has already been added. What is the proper syntax?
See original GitHub issueI 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!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Invoke-ScriptAnalyzer (PSScriptAnalyzer) - PowerShell
Invoke -ScriptAnalyzer evaluates scripts or module files (.ps1, .psm1, and .psd1 files) based on a collection of best practice rules and returns objects...
Read more >Item with Same Key has already been added
This error is fairly self-explanatory. Dictionary keys are unique and you cannot have more than one of the same key. To fix this,...
Read more >An item with the same key has already been added
I always receive this error "An item with the same key has already been added." when I try to start a pipeline release...
Read more >PowerShell
Invoke -ScriptAnalyzer will analyze one or more files that you identify using the rules that are in use by Script Analyzer, notifying you...
Read more >9 PowerShell Code Signing Best Practices for ...
Have a specific script signing policy for each key. 7. Don't Sign All Your Scripts With the Same Key. Use a dedicated key...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@thomasrayner currently we are targeting a 1.19.1 release in about two weeks (likely the last week in July) however this is truly not a promise/commitment–just a good faith estimate…we are hoping to get another bug fix into this release, and then prioritize the release amongst other commitments
I’m in favour of a 1.19.1 release