Skip to content

PSUseUsingScopeModifierInNewRunspaces has false positive when using -ArgumentList on Invoke-Command #1504

Description

@jegannathanmaniganadan

Steps to reproduce

 # $sb = {
Invoke-Command -Session $psSession -ArgumentList $path -ErrorAction Stop -ScriptBlock {
Param ($Foo)
return $Foo
}}
# Invoke-ScriptAnalyzer -ScriptDefinition [scriptblock]$sb | ft -a
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseUsingScopeModifierInNewRunspaces Warning 3 The variable '$Foo' is not declared within this ScriptBlock, and is missing the 'Using:' scope modifier.
PSUseUsingScopeModifierInNewRunspaces Warning 5 The variable '$Foo' is not declared within this ScriptBlock, and is missing the 'Using:' scope modifier.

Expected behavior

$Foo should not get flagged

Actual behavior

$Foo is being flagged violating PSUseUsingScopeModifierInNewRunspaces.

Environment data

# $PSVersionTable
Name Value
---------
PSVersion 5.1.18362.752
PSEdition Desktop
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
BuildVersion 10.0.18362.752
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

@mattpwhite

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