Skip to content

Powershell PSScriptAnalyzer, error in PSUseDeclaredVarsMoreThanAssignments #1226

@ingemar-hn

Description

@ingemar-hn

System Details

  • Operating system name and version: Windows 10
  • VS Code version:
    Version 1.22.0-insider
    Commit 5450fdc79778b5a76a27ea7e5fd68e9ebbe44107
    Date 2018-03-12T05:15:51.483Z
    Shell 1.7.9
    Renderer 58.0.3029.110
    Node 7.9.0
    Architecture x64
  • PowerShell extension version: 1.6.0
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:

code -v
$pseditor.EditorServicesVersion
code --list-extensions --show-versions
$PSVersionTable

PS [A] > code -v
1.17.2
b813d12980308015bcd2b3a2f6efa5c810c33ba5
PS [A] > $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      6      0      0


PS [A] > code --list-extensions --show-versions
ms-vscode.csharp@1.13.1
ms-vscode.PowerShell@1.5.1
ms-vsts.team@1.122.0
secanis.jenkinsfile-support@0.1.0
slevesque.vscode-autohotkey@0.2.1
PS [A] > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Error occurs in the below code:

$a = 0
foreach ($i in 0..3) {
        $a = 1
}
0..3 | ForEach-Object {
        $a = 1
}
$a

In the first loop it works as it should. In the second $a is reported to be assigned but never used.

Attached Logs

Follow the instructions in the README
about capturing and sending logs.
logs.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions