You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warning about unused PSNativeCommandArgumentPassing preference variable #2092
I'm aware that I can suppress this warnings by applying [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','')] attribute, but it is wrong, because I still want to receive warnings about other unused variables.
Actual behavior
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseDeclaredVarsMoreThanAssignment Warning test.ps1 1 The variable 'PSNativeCommandArgumentPassing' is assigned
s but never used.
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.20348
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.24.0
Yep. It's the little things like this that sting. I sometimes work around it by adding a line like [void]$PSNativeCommandArgumentPassing or Write-Verbose $PSNativeCommandArgumentPassing but you're right that it shouldn't be necessary for preference variables. Does PSScriptAnalyzer maintain a list of ignored variable names for the PSUseDeclaredVarsMoreThanAssignment test?
Activity
SamErde commentedon Apr 4, 2025
Yep. It's the little things like this that sting. I sometimes work around it by adding a line like
[void]$PSNativeCommandArgumentPassingorWrite-Verbose $PSNativeCommandArgumentPassingbut you're right that it shouldn't be necessary for preference variables. Does PSScriptAnalyzer maintain a list of ignored variable names for the PSUseDeclaredVarsMoreThanAssignment test?bergmeister commentedon Apr 4, 2025
We have a list of excluded special variables, it seems that variable is new and needs to be added:
PSScriptAnalyzer/Engine/SpecialVars.cs
Line 169 in 2287a13