-
Notifications
You must be signed in to change notification settings - Fork 513
Powershell Code format (PSScriptAnalyzer) flags variable as unused #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm running into this issue in some of my scripts, especially when dealing with In this use-case, it's for a logging object that gets sent in an email for automation errors |
I am running into this issue in several of my scripts. If ($script:DNsThatHaveBeenACLReset -notcontains $MyDN.ToLower())
} The analyzer is only flagging the instance of the variable within the ForEach-Object portion of this. |
Thanks for this! I tried running Script Analyzer on its own against the original repro and I'm seeing the warning. Here's the repro: In the file $a = 0
$b = @(1, 2)
$b | ForEach-Object {
$a += 1
}
Write-Host $a in a terminal: Install-Module -Name PSScriptAnalyzer
Invoke-ScriptAnalyzer -Path path/to/repro.ps1 -Settings PSGallery -Recurse The output:
Let me go ahead and open this in https://github.com/PowerShell/PSScriptAnalyzer |
Actually, it looks like it's already open here!: PowerShell/PSScriptAnalyzer#827 Thanks again for the report - feel free to add more details and +1 that issue! |
From @cryptonym64 on June 15, 2017 19:15
Steps to Reproduce:
code this:
$a = 0
$b = @(1,2)
$b | ForEach-Object {
$a += 1
}
Write-Host $a
Ctrl-Alt-F to format.
Notice that it warns:
file: 'untitled:Untitled-1' severity: 'Warning' message: 'The variable 'a' is assigned but never used. (PSUseDeclaredVarsMoreThanAssignments)' at: '4,5' source: 'PSScriptAnalyzer'
Copied from original issue: microsoft/vscode#28835
The text was updated successfully, but these errors were encountered: