Description
Before submitting a bug report:
- Make sure you are able to repro it on the latest released version
- Perform a quick search for existing issues to check if this bug has already been reported
Steps to reproduce
ran:
Invoke-ScriptAnalyzer -Path .\dummy.ps1 -Recurse -Severity 'warning' -Verbose
dummy.ps1
Invoke-Command -ComputerName $server -SessionOption $sessionOptions -ScriptBlock {
$var="value"
$var="newvalue"
}
Expected behavior
No error
Actual behavior
VERBOSE: Settings object could not be resolved.
VERBOSE: Performing the operation "Analyzing path with Recurse=True" on target
"D:\GitLab-Runner\builds\armEq4Je\0\xxxx\xxxx-managed-scripts\Infra\roles\role_check_server_sanity\files\Script\dummy.ps1".
VERBOSE: Performing the operation "Analyzing file
D:\GitLab-Runner\builds\armEq4Je\0\xxxx\xxxx-managed-scripts\Infra\roles\role_check_server_sanity\files\Script\dummy.ps1" on target
"D:\GitLab-Runner\builds\armEq4Je\0\xxxx\xxxx-managed-scripts\Infra\roles\role_check_server_sanity\files\Script\dummy.ps1".
VERBOSE: Analyzing file: D:\GitLab-Runner\builds\armEq4Je\0\xxxx\xxxx-managed-scripts\Infra\roles\role_check_server_sanity\files\Script\dummy.ps1
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Running PSAvoidAssignmentToAutomaticVariable rule.
VERBOSE: Running PSAvoidDefaultValueSwitchParameter rule.
VERBOSE: Running PSAvoidDefaultValueForMandatoryParameter rule.
VERBOSE: Running PSAvoidUsingEmptyCatchBlock rule.
VERBOSE: Running PSAvoidGlobalAliases rule.
VERBOSE: Running PSAvoidGlobalFunctions rule.
VERBOSE: Running PSAvoidGlobalVars rule.
VERBOSE: Running PSAvoidInvokingEmptyMembers rule.
VERBOSE: Running PSAvoidNullOrEmptyHelpMessageAttribute rule.
VERBOSE: Running PSAvoidOverwritingBuiltInCmdlets rule.
VERBOSE: Running PSReservedCmdletChar rule.
VERBOSE: Running PSReservedParams rule.
VERBOSE: Running PSAvoidShouldContinueWithoutForce rule.
VERBOSE: Running PSAvoidUsingDeprecatedManifestFields rule.
VERBOSE: Running PSAvoidUsingInvokeExpression rule.
VERBOSE: Running PSAvoidUsingPlainTextForPassword rule.
VERBOSE: Running PSAvoidUsingWMICmdlet rule.
VERBOSE: Running PSAvoidUsingWriteHost rule.
VERBOSE: Running PSMisleadingBacktick rule.
VERBOSE: Running PSMissingModuleManifestField rule.
VERBOSE: Running PSPossibleIncorrectComparisonWithNull rule.
VERBOSE: Running PSPossibleIncorrectUsageOfRedirectionOperator rule.
VERBOSE: Running PSReviewUnusedParameter rule.
VERBOSE: Running PSUseApprovedVerbs rule.
VERBOSE: Running PSUseBOMForUnicodeEncodedFile rule.
VERBOSE: Running PSUseCmdletCorrectly rule.
VERBOSE: Running PSUseCompatibleCmdlets rule.
VERBOSE: Running PSUseDeclaredVarsMoreThanAssignments rule.
VERBOSE: Running PSUseLiteralInitializerForHashtable rule.
VERBOSE: Running PSUseProcessBlockForPipelineCommand rule.
VERBOSE: Running PSUsePSCredentialType rule.
VERBOSE: Running PSShouldProcess rule.
VERBOSE: Running PSUseShouldProcessForStateChangingFunctions rule.
VERBOSE: Running PSUseSingularNouns rule.
VERBOSE: Running PSUseSupportsShouldProcess rule.
VERBOSE: Running PSUseToExportFieldsInManifest rule.
VERBOSE: Running PSUseUsingScopeModifierInNewRunspaces rule.
**Invoke-ScriptAnalyzer : An item with the same key has already been added.**
+ CategoryInfo : InvalidOperation: (D:\GitLab-Runne...Check.dummy.ps1:String) [Invoke-ScriptAnalyzer], Ar
gumentException
+ FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerComm
and
VERBOSE: Running PSUseUTF8EncodingForHelpFile rule.
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseDeclaredVarsMoreThanAssignment Warning ServerSani 2 The variable 'var' is assigned but never used.
s tyCheck.du
mmy.ps1
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
$error[0] | Select-Object *
writeErrorStream : True
PSMessageDetails :
Exception : System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseUsingScopeModifierInNewRunspa ces.SyntaxCompatibilityVisitor.FindVarsInAssignmentAsts(Ast ast) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseUsingScopeModifierInNewRunspa ces.SyntaxCompatibilityVisitor.AnalyzeScriptBlock(ScriptBlockExpressionAst scriptBlockExpressio nAst) at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseUsingScopeModifierInNewRunspa ces.SyntaxCompatibilityVisitor.VisitScriptBlockExpression(ScriptBlockExpressionAst scriptBlockE xpressionAst) at System.Management.Automation.Language.ScriptBlockExpressionAst.InternalVisit(AstVisitor v isitor) at System.Management.Automation.Language.CommandAst.InternalVisit(AstVisitor visitor) at System.Management.Automation.Language.PipelineAst.InternalVisit(AstVisitor visitor) at System.Management.Automation.Language.StatementBlockAst.InternalVisit(AstVisitor visitor, ReadOnlyCollection
1 traps, ReadOnlyCollection`1 statements, AstVisitAction action)
at System.Management.Automation.Language.NamedBlockAst.InternalVisit(AstVisitor visitor)
at System.Management.Automation.Language.ScriptBlockAst.InternalVisit(AstVisitor visitor)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseUsingScopeModifierInNewRunspa
ces.AnalyzeScript(Ast ast, String fileName)
at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass83_1.b__2()
TargetObject : D:\GitLab-Runner\builds\armEq4Je\0\xxxx\xxxx-managed-scripts\Infra\roles\role_check_server_sanity\files\Script\dummy.ps1
CategoryInfo : InvalidOperation: (D:\GitLab-Runne...dummy.ps1:String) [Invoke-ScriptAnalyzer], ArgumentE
xception
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace :
PipelineIterationInfo : {0, 1, 0}
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.3471
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3471
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0