ReviewUnusedParameter does not capture parameter usage within a scriptblock
See original GitHub issueSteps to reproduce
Run Invoke-ScriptAnalyzer
against the following with the new 1.19.0 release.
function foo {
Param(
$MyParameter
)
Get-Item| ForEach-Object { Get-ChildItem $MyParameter }
}
Expected behavior
No rule violations.
Actual behavior
The new ReviewUnusedParameter
rule doesn’t notice the usage. I suspect this is similar to the limitation of the AvoidUsingCmdletAliases
rule though. Not sure if we should relax the ReviewUnusedParameter
rule in this case to search nested scriptblocks inside a function scope.
cc @mattmcnabb @rjmholt @JamesWTruher
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSReviewUnusedParameter Warning test.ps1 4 The parameter 'MyParameter' has been declared but not used.
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.1.0-preview.2
PSEdition Core
GitCommitId 7.1.0-preview.2
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:31
- Comments:27 (3 by maintainers)
Top Results From Across the Web
ReviewUnusedParameter - PowerShell
This rule identifies parameters declared in a script, scriptblock, or function scope that have not been used in that scope.
Read more >Examples/cTentacleAgent_ListeningTentacle.psm1 4.0.957
SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="ReviewUnusedParameter does not capture parameter usage within a scriptblock.
Read more >Why does an argument passed into a script block fail to ...
The reason is because the entire xss variable is being printed as an argument and is not named inside the job. It's given...
Read more >What is wrong with this Command? Warning" 'Cannot ...
Warning" 'Cannot evaluate parameter 'NewName' because argument is specified as a script block and there is no input'.
Read more >Chris Bergmeister
Another new rules is soon coming to the next version of #PSScriptAnalyzer: ReviewUnusedParameter warns if a parameter is declared in ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To suppress
PSReviewUnusedParameter
for a specific parameter you should setSuppressMessageAttribute
’scheckId
to the name of the parameter without the$
prefix.To add to the list, we’re also seeing this fail with
Invoke-Command -ScriptBlock {}
(though this using$using:varName
), and with usage via@PSBoundParameters
, which is frustrating. I’m unsure what to suggest, though.