Closed
Description
It doesn't seem that variables have to be used more than their assignments; they can also be used the same number of times. You should clarify the language by saying something like "greater than or equal to their assignments".
You should also mention that the variable must be used within the same scope in which it was declared or else it won't be considered to be "used".
I have an example...
**$foo | for-eachobject {if($_ -eq $false){$bar = $true}}
if($bar){write-host "You are still going to get a PSUseDeclaredVarsMoreThanAssignments error even though you are using the bar variable here."}**
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: e77c7bc9-9fda-5e82-def1-d1aaa0f62d0a
- Version Independent ID: 33d40987-b49b-186f-1daa-d54a2e76494c
- Content: UseDeclaredVarsMoreThanAssignments - PowerShell
- Content Source: reference/docs-conceptual/PSScriptAnalyzer/Rules/UseDeclaredVarsMoreThanAssignments.md
- Product: powershell
- Technology: powershell-conceptual
- GitHub Login: @sdwheeler
- Microsoft Alias: sewhee