PowerShell / PowerShell/PSScriptAnalyzer
Global variables are erroneously reported as "never used"
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
System Details Output
### VSCode version: 1.36.1 2213894ea0415ee8c85c5eea0d0ff81ecc191529 x64
### VSCode extensions:
bierner.lit-html@1.11.0
mikeburgh.xml-format@1.0.2
MS-CEINTL.vscode-language-pack-de@1.36.2
ms-vscode.powershell@2019.5.0
msjsdiag.debugger-for-chrome@4.11.6
slevesque.vscode-hexdump@1.7.2
### PSES version:
### PowerShell version:
Name Value
---- -----
PSVersion 5.1.16299.1146
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.1146
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Issue Description
PowerShell extension reports global variables as assigned but not used when they are not used from within a .psm1 module file. However, global variables may be used by scripts outside that module importing it.
Expected Behaviour
Global variables should never be reported as being unused.
Actual Behaviour
PowerShell extension reports global variables as assigned but not used when they are not used from within a .psm1 module file.

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files, tests, or entry points are named. Start by locating the analyzer logic that reports assigned-but-unused variables and the tests covering module or global-variable scope. Confirm the current behavior, then update the relevant test expectations so global variables are not reported as unused and run the affected analyzer tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100