Closed
Description
Steps to reproduce
Save this script to a file test.ps1
:
$PSNativeCommandArgumentPassing = 'Legacy'
'Hello, World!'
Call Invoke-ScriptAnalyzer
cmdlet:
Invoke-ScriptAnalyzer -Path .\test.ps1
Expected behavior
Empty output; no warnings.
$PSNativeCommandArgumentPassing is a preference variable.
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