Using "Visual Studio code" with interactive Powershell window like Powershell ISE - powershell

I'm new to Visual Studio code so thanks in advance for the help.
I often use the PowerShell ISE with an interactive PowerShell window. I open it, type a few commands, then run a script (such as opening a PowerShell session with Office 365) and then type a few more commands.
Is there any way to do the same thing with Visual Studio code? I see a way to run scripts and debug them but not have them complete but the PowerShell window still stay around so I can continue working.

Decided to convert to answer, since this is a bit too much for comments:
Go to settings > user settings and change "terminal.integrated.shell.windows" to:
"C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
Ctrl + Shift + ` opens the terminal. Using the + button on the terminal window you can launch additional powershell instances.
Also there's an extension that allows for launching several different terminals under the same VSCode process (cmd,powershell,bash,etc). Minor nuance, shells are being started with the same permissions VSCode has, but you can re-elevate once inside the shell.
References:
https://code.visualstudio.com/docs/editor/integrated-terminal
https://code.visualstudio.com/docs/customization/userandworkspace
https://github.com/Microsoft/vscode/issues/10893
Edit: but I would say its not really convenient, terminal takes away too much space on the screen (well, unless you have like 2k or 4k display), so I use powershell + vscode.

Related

PowerShell console in Visual Studio Code: How to copy-paste?

I cannot Copy-Paste from the Visual Studio Code console. In ISE one can copy-paste some of the output, but it does not seem to be possible in Visual Studio Code Terminal. How can I copy-paste the output from the console when running PowerShell commands? I have the PowerShell Extension.
Ctrl+C and Ctrl+V for copying / pasting work as-is in Visual Studio Code's integrated terminal.
By contrast, right-click behavior is configurable:
On Windows, the default behavior is to copy, if text is currently selected, and paste otherwise - as in regular console windows.
To get the same behavior as in the Windows PowerShell ISE, i.e. to instead show a shortcut menu, which contains Copy and Paste commands, add the following line to your settings.json file (before the closing }):
"terminal.integrated.rightClickBehavior": "default",
Alternatively, use the settings GUI (press Ctrl+,):
Note:
The screenshot was taken on macOS, where selectWord is the default setting; on Windows, it is copyPaste, with the behavior as described above.
Also note the GUI's convenient search feature: typing right click in the search field was sufficient to locate the relevant setting.

How to switch default run terminal for VSCode with Powershell

When I select RUN for my PowerShell script it executes in my "Integrated PowerShell Console" which is running PowerShell 7.x.
Some of my scripts use commands that are not available in PS7 (yet?) but works in PS5.
I have a second Terminal running in VSCode running PS5 and I can paste the script there and it works.
How can I switch the functionality of RUN (F5) to execute the script in my second terminal window?
Thank you Shivam Jha for the link.
I tried to map F5 to "workbench.action.terminal.runActiveFile: Run the active file in the terminal instance." and that works except it can only run code from files, not code just entered in the editor and not yet saved.
The solution then is to have F5 mapped to workbench.action.debug.run and CTRL+F5 mapped to workbench.action.terminal.runActiveFile.
This way I can have several PowerShell terminals active and use CTRL+F5 to run the active file in any of them.
This is just a guess, untested, but to me, it seems promising.
Open two instances of vscode, open the same folder in both, and open the two different terminals, one in each instance. If it still takes the default terminal even if you open another one in advance, try running in interactive window. Also check whether running just a selection (then just select the whole file) might influence the chosen output terminal.

F8 or "Run Selection" not working in VS Code while trying to run powershell commands in terminal

I am using VS Code and i have my powershell terminal in VS Code as well as Powershell ISE. I have my own personal script file in the form of .ps1 which has some list of commands. When i select a command in the file and right click and choose "Run Selection" , that doesn't get reflected in the Powershell Terminal in VS code. I even tried Function + F8 key of the laptop, still the same. Any idea what do i need to do to fix this.
I had the same issue, F8 stopped running selected script suddenly. Had to reinstall the PowerShell extension for VScode and it fixed it.
Check key bindings as well by hitting Ctrl+K, Ctrl+S and search "Run Selection". This should be a sub function of the PowerShell extension.
I ran into a similar problem and I came into the solution. Just install the powershell extension for VS code and you'll see the Run Selection/F8 work.

Using Powershell ISE's intellisense in other terminal

I'm a big fan of powershell ISE as a terminal. It has intellisense and syntax highlighting built in the shell and I just use it instead of the regular shell for everyday commands.
I would like to use Visual Studio Code instead, because the editor is much more powerfull and has support for a whole lot of languages and format. However the integrated shell is you basic Powershell terminal : no intellisense, no coloring (even with Powershell 5 installed on my computer).
Is there any way to add intellisense and coloring to my terminal, or use ISE's terminal in VSCode? or is there a plugin somewhere adressing these issues?
The integrated PowerShell terminal on Visual Studio Code does have intellisense, so I'm unclear what you require here, are you sure it's not set to cmd.exe instead ?
On another note, follow this setup guide. In case you haven't already installed the PowerShell Extension.

VS Code: How to disable Security Warning for PowerShell

I've been trying to use VS Code a bit more lately as a replacement for Notepad++ but there is one feature in VS Code that is super annoying. I'll be typing away on a PowerShell .ps1 file (either locally on my work machine or on a file from another server via UNC path) and a Security Warning will pop-up at the top:
And after a few seconds a PowerShell Output pops open at the bottom:
I'm not sure why these windows keep popping open. I'm assuming my PowerShell script is running in the background or something, but how do I disable these windows? This is the main reason why I switch back to Notepad++ or use Atom.
BTW: I do not want my PowerShell scripts to run within VS Code while I'm coding.