Skip to content

PSScriptAnalyzer and ForEach-Object, says variable "is assigned but never used" but it is #1639

@mlduber

Description

@mlduber

Steps to reproduce

'foo' | ForEach-Object { $guy = 'bar' }; $guy

Expected behavior

Zero problem. Scope issue should be expected with Invoke-Command but not with ForEach-Object.

Actual behavior

The variable 'guy' is assigned but never used.PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)

image

Environment data

PSScriptAnalyzer module version is 1.19.0.

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