$PSVersionTable:Name|Value
---|---
PSVersion|5.1.16299.64
PSEdition|Desktop
PSCompatibleVersions|{1.0, 2.0, 3.0, 4.0...}
BuildVersion|10.0.16299.64
CLRVersion|4.0.30319.42000
WSManStackVersion|3.0
PSRemotingProtocolVersion|2.3
SerializationVersion|1.1.0.1
Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:
PowerShell Integrated Console
PS > code -v
1.18.1
929bacba01ef658b873545e26034d1a8067445e9
PS > $pseditor.EditorServicesVersion
Major Minor Build Revision
----- ----- ----- --------
1 5 1 0
PS > code --list-extensions --show-versions
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
PS > $PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.64
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.64
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Note: I did search for similar issues, but I could not find any.
In a script I am writing, I have a check against $WhatIfPreference. To test this in a debugging session in VS Code, I pass the -WhatIf flag using the PowerShell Launch Current File w/Args Prompt debug option.
Test case:
[CmdletBinding(SupportsShouldProcess=$true)]
Param()
If ($WhatIfPreference) {
Write-Output "WhatIf enabled"
} Else {
Write-Output "WhatIf disabled"
}
A breakpoint has been set on the If line. Upon entering a debugging session and hitting the breakpoint, hovering the mouse over $WhatIfPreference will show $false, no matter if -WhatIf has been set. This is true for the Variables and Watch panels as well. However, the script will evaluate the variable correctly. If -WhatIf is set, the test evaluates as true.
Please let me know if there's any more information or context I should provide.
I believe this has to do with the fact that when you debug a script, that script is dot sourced into the PowerShell Integrated Console's global session. This is not one of my favorite things about the debugger but we were trying to reach some parity with the ISE debugger. Ironically this scenario works as expected in ISE. Go figure. Anyway, thanks for reporting the issue.
This is probably related to: https://github.com/PowerShell/PowerShell/issues/4568
If you set $whatifpreference prior to running the script, it will report $true.
This same behavior applies for $verbosepreference and $debugpreference as well

It happens also if you set a breakpoint and call with & vs dotsource, so I don't think https://github.com/PowerShell/vscode-powershell/issues/1109#issuecomment-346528932 is correct.
It may be related to watch commands not running within the script PSCmdlet scope or something? For instance, you can't "watch" things like $PSScriptRoot or $PSBoundParameters, maybe this preference falls into that category of things.

Most helpful comment
I believe this has to do with the fact that when you debug a script, that script is dot sourced into the PowerShell Integrated Console's global session. This is not one of my favorite things about the debugger but we were trying to reach some parity with the ISE debugger. Ironically this scenario works as expected in ISE. Go figure. Anyway, thanks for reporting the issue.