vscode-powershell
vscode-powershell copied to clipboard
Debug Session Clutters Terminal Command History
System Details
- Operating system name and version:
- VS Code version:
- PowerShell extension version:
- Output from
$PSVersionTable:
PS C:\Temp> code -v
1.13.0
376c52b955428d205459bea6619fc161fc8faacf
PS C:\Temp> $pseditor.EditorServicesVersion
Major Minor Build Revision
----- ----- ----- --------
1 3 2 0
PS C:\Temp> code --list-extensions --show-versions
[email protected]
[email protected]
PS C:\Temp> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.1198
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1198
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Issue Description
I am experiencing a problem with commands being inserted into the command history by a debugging session. The additional commands seem to be related to the debugging session. I have reproduced this issue with a simple .ps1 file containing a single variable assignment, with a breakpoint set on the line.
Repro.ps1: $x=1
The entires I'm referring to are Ids 5-9 in the below transcript. The "Get-Variable" entries in the command history appear to be triggered by hovering the mouse over a variable in the editor window to view its value. I'm not sure what triggers the ones.
PS C:\Projects\SQLServerDBA\PowerShellModulesV2> c:\Temp\repro.ps1
PS C:\Temp> get-history
Id CommandLine
-- -----------
1 get-module
2 gci c:\temp\
3 c:\Temp\repro.ps1
PS C:\Temp> c:\Temp\repro.ps1
Hit Line breakpoint on 'C:\Temp\repro.ps1:1'
[DBG]: [DBG]: PS C:\Temp>
PS C:\Temp> Get-history
Id CommandLine
-- -----------
1 get-module
2 gci c:\temp\
3 c:\Temp\repro.ps1
4 get-history
5 @{ 'computerName' = $env:ComputerName; 'processId' = $PID; 'instanceId'...
6 Get-Variable
7 Get-Variable
8 $global:__psEditorServices_CallStack = Get-PSCallStack; $global:__psEdi...
9 Get-Variable
10 c:\Temp\repro.ps1
Thanks Mike! This is coming from PowerShell, I had filed a bug on it some time ago:
https://github.com/PowerShell/PowerShell/issues/3109
I'll see if I can find a workaround that doesn't cause these commands to be added to your history.
@SydneyhSmith @TylerLeonhardt
EDIT: Can Reproduce now:

Get-History is still dirty FWIW. Until an option is added to the debugger API to skip adding to history, there won't really be a good way to fix that though :/
Any updates on this? Just wasted a few hours debugging a Start-Transcript call in my code only to realize that the strange logs was caused by the debugger itself from the VS Code PowerShell extension.
Um, well, it is fixed in the preview as of right now, but our fix might not be viable long-term. Give the preview a try!
@TheOnlyWei Did you get a chance to try the Preview?
@andschwa The 7.3-preview does not seem to list this fix in the change description. I switched VS code integrated console to PowerShell Core 7.3-preview anyway and it didn't fix anything. Did it work for you on your machine?
The latest code is available in the PowerShell Preview for VS Code, and includes a myriad of fixes. Could you verify if this issue still reproduces using the preview extension? Please note that this preview is likely to include other bugs, and you should feel free to file new issues for those so we can work through them. Thanks again!
@TheOnlyWei See my reply above, I meant the preview of the extension, not PowerShell's preview version itself (sorry for the confusion). Thanks!
@andschwa The output clutter is greatly reduced, but still getting some stuff like the following that is not output in the console:
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Global"
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Script"
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Local"
PS>CommandInvocation(Get-Variable): "Get-Variable"
>> ParameterBinding(Get-Variable): name="Scope"; value="Local"
Ah! Thanks @TheOnlyWei, can definitely fix the rest of this!
Well, that's interesting. I'm actually not sure why those last bits are showing up, as the default for AddToHistory is false, so they shouldn't be.
Going to leave this one open to track the remaining work.
Hey @TheOnlyWei can you test the latest release and let me know both what you see and how you test it? I'd like to get this finished if I can.
Closing this as resolved