vscode-powershell
vscode-powershell copied to clipboard
IntelliSense reports warning incorrectly in foreach-object begin parameter
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all open and closed issues to ensure it has not already been reported.
- [X] I have read the troubleshooting guide.
- [X] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- [X] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
- [ ] If this is a security issue, I have read the security issue reporting guidance.
Summary
Incorrect warning "variable assigned but never used" in foreach-object, parameter -begin
PowerShell Version
PSVersion 7.3.1
PSEdition Core
GitCommitId 7.3.1
OS Microsoft Windows 10.0.22623
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visual Studio Code Version
1.74.3
97dec172d3256f8ca4bfb2143f3f76b503ca0534
x64
Extension Version
[email protected]
[email protected]
Steps to Reproduce
code this: ForEach-Object -Begin{ $a=1 } -Process{ $a++ } -End{ $a }
Notice that it warns: Msg: The variable 'a' is assigned but never used. PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)
Visuals

Logs
No response
Duplicate of PowerShell/PSScriptAnalyzer#1641
Thanks for the report! We're tracking this in the linked issue above.
This issue has been marked as external. It has been automatically closed for housekeeping purposes.