0

Is it possible to hide the PSScriptAnalyzer messeage in Visual studio code "The variable is assigned but never used" ?

I tried with: [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments')] But then the handle is not cached, and I cant get an exitcode

Code:

        $SplatArgs = @{
        FilePath    = $FilePath
        NoNewWindow = $true
        Passthru    = $true
        ErrorAction = "Stop"
    }

 $Execute = Start-Process @SplatArgs
        [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments')]
        $Handle = $Execute.Handle
        $Execute.WaitForExit()

The code is working fine, it's just the error message I want gone, initially I got the idea from :

Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait

How to silence a warning or even better if you know why: is assigned but never

BenDK
  • 131
  • 2
  • 7
  • It should be `$Handle = $Execute.Handle`, not `$Handle = Execute.Handle`. Is it a typo on your side ? – Zilog80 Jun 20 '21 at 08:13
  • Anyway, `$Execute.Handle | Out-Null` instead of `$Handle = $Execute.Handle` should do the trick, as there is no more assignation (as the workaround only requires `Handle` property to be referenced). – Zilog80 Jun 20 '21 at 08:30
  • 1
    Yes typo, your suggestion works perfectly, can't believe i didn't try that myself - thanks – BenDK Jun 20 '21 at 09:07

0 Answers0