I'm currently using version 0.10.0 of the PowerShell extension within Visual Studio Code. It used to be that the run space was reset between each run of a script so if there were changes made to a module, the updated module was imported into the script.
However, for some reason, the PowerShell run space is no longer being reset so a change in a module is not picked up during the next run.
Is there a setting within the PowerShell extension that will ensure the run space is reset between each run of a script?
Now, switch back to your PowerShell file in the editor window and set breakpoints where you need them. Choose PowerShell Launch Current File option in the Debug menu above, and click on the green triangle to run the script in the debugger mode. The debugger will stop at the first breakpoint it encounters.
PowerShell Extension Once you install the extension, you can create a new PowerShell script by pressing Ctrl+N and then saving it as a PS1 file using Ctrl+S . Once it is saved as a PS1, VS Code will identify the file as a PowerShell script. From there, you can execute the PowerShell script by press F5 .
PowerShell in Visual Studio Code. PowerShell is a task-based command-line shell and scripting language built on . NET, which provides a powerful toolset for administrators on any platform.
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:
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With