PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.85k stars 373 forks source link

PSReviewUnusedParameter incorrectly triggered #1827

Closed DarkLite1 closed 2 years ago

DarkLite1 commented 2 years ago

Steps to reproduce

Param (
    [String]$SamAccountName = 'bob'
)

Get-ADGroupMember 'group' | Get-ADUser | Where-Object {
        ($_.SamAccountName -ne $SamAccountName)
}

image

Expected behavior

The variable is clearly used in the script, so it shouldn't show the message.

Environment data

>  $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14393.5127
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.5127
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.20.0
1.19.1
1.19.0
1.18.3
1.20.0

Possibly related to #1472 , but there's no activity there anymore. So I thought I would bring this back to your attention.

StevenBucher98 commented 2 years ago

Thanks for opening this issue, this is a super tricky one that is pretty well explained in the issue you linked.

bergmeister commented 2 years ago

Yes, this is a duplicate of #1472. Thanks for reporting though.

ghost commented 2 years ago

This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes.