Closed
Description
Given the following code
$msg = @()
@("a", "b") | ForEach-Object { $msg += $_ }
Write-Information $msg -InformationAction Continue
I get the following warning:
- The variable 'msg' is assigned but never used. (line 2)
I realize that this generates a new array each time, but it is both being assigned to and read, so this appears to be a false positive.
Another similar scenario:
$params = (@{"a" = 1; "b" = 2}).GetEnumerator() |
ForEach-Object { $m = @{} } { $m[$_.Name] = $_.Value } { $m } # foreach begin{} process{} end{}
$params
- The variable 'm' is assigned but never used. (line 2)