How can you reset the PowerShell runspace within Visual Studio Code

I still dont have a good answer for this, but this is what I did to mitigate the problem during development.

I noticed that VS Code was caching the variables between each run, and that it effectively ran the script as if it was a REPL.

Due to the nature of PowerShell scopes, you can wrap your code in an Invoke-Command -ScriptBlock {} and as variables are not accessible outside of their script block, you can re-run the code without worrying about leaving objects in vs code.


The setting powershell.debugging.createTemporaryIntegratedConsole which is now available with in the PowerShell plugin for Visual Studio Code solved my problem.

The setting is defaulted to false so it must be enabled before it will work.

When it is set to true the PowerShell session is reset each time you try to debug through a script. This means that:

  • Constant variables can be reset
  • Updates to PowerShell modules will be pulled into the session

It can be enabled by adding the following line to the user settings JSON file

"powershell.debugging.createTemporaryIntegratedConsole": true

Or enable it in the Preferences under File -> Preferences -> Settings and search for Create Temporary Integrated Console