Remove if statement to prevent InvalidOperation error by jakekerr · Pull Request #13350 · PowerShell/PowerShell

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra if block inside shouldn't be needed, I don't think?

If the variable exists, Get-Variable -ValueOnly will return its value as-is, whether that's true or false (or anything else, for that matter).

If the variable doesn't exist, it'll return $null which is treated by if statements the same way as $false. 🙂