How to change integrated PowerShell terminal in VS Code - powershell

I'm fairly new to VS Code and I have been trying to setup the program/workspace (one and the same for me).
I've setup all the recommended settings for PowerShell, but I have been trying to change the integrated terminal to v7 - each time it loads is with V5.1.
Firstly, I know there are many answers out there - I have tried them all. The problem is that most of them are out of date now.
I ran into an answer by Ger83 in How to Change Visual Studio Code 'Powershell Integrated Console'?. There, he describes the deprecated features and issues with the PowerShell Extension. (Since Ger83 had the answers, I was going to leave comments - not enough reputation - or send a private message - does not exist - so I had to create a whole new question to get an answer.)
So, is there a way to change the PowerShell integrated console from v5.1 to v7 while also using the PowerShell Extension?
My settings.json, I believe, are setup correctly:
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
I tried to turn off the PowerShell extension, but as a result, I lost the ability to run PowerShell scripts from the editor.
With the extension on, I noticed that the language in the bottom-right corner is shown as v5.1. I don't know if it is possible to change this.
PowerShell Language screenshot showing v5.1
If there is no way to change the integrated console to v7, are there any workarounds to enable easy running of a script directly to the PowerShellv7 console? This may be a shortcut or setting.
Edit: Answer is provided by mklement0 in the comments.

Related

New way to specify Powershell 7 in Visual Studio Code?

I am trying to replace the default Powershell 5 with the newer Powershell 7, on Windows 11.
99% of the solutions on the internet say to add this to settings.json.
"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
However, this now gives a red squiggly line with the following message:
This is deprecated, the new recommended way to configure your default
shell is by creating a terminal profile in
#terminal.integrated.profiles.windows# and setting its profile name
as the default in #terminal.integrated.defaultProfile.windows#. This
will currently take priority over the new profiles settings but that
will change in the future.(2)
There is one possibly related thread, but it only deals with defaulting it to the native Command Prompt, rather than re-jigging things to Powershell 7.
So, what is the correct new way to provide Powershell 7s path to VS Code, and also set it as the default terminal?
In earlier VSCode (Visual Studio Code) versions, the "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings determined the default shell and its startup arguments for the integrated terminal.
These have been superseded by shell profiles, defined via "terminal.integrated.profiles.*" properties, and an associated "terminal.integrated.defaultProfile.*" property that contains the name of the profile to use by default, as shown below (use > Preferences: Open Settings (JSON) from the command palette to open your settings.json file):
"terminal.integrated.profiles.windows": {
"PowerShell_7": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"icon": "terminal-powershell"
}, // ...
}
// Make the profile defined above the default profile.
"terminal.integrated.defaultProfile.windows": "PowerShell_7"
Note:
The above defines the default general-purpose shell for Visual Studio Code's integrated terminal.
For information on how to specify what PowerShell version to use with the special-purpose PIC (PowerShell Integrated Console) that comes with the PowerShell extension (for authoring and debugging PowerShell code), see this answer.
I would have expected Visual Studio Code to use your v7 version automatically, as it - if installed - normally takes precedence over Windows PowerShell.

Visual Studio 2019 Developer PowerShell v16.9.4 not working

I have an issue or question with regards to Visual Studio 2019 Developer PowerShell v16.9.4.
I have Visual Studio Professional 2019, Version 16.9.4.
When I right click on my Solution and select Open in Terminal then Visual Studio 2019 Developer PowerShell v16.9.4 opens... but it doesn't allow me to put/execute any command son it.
My impression is that it's not fully loaded or something...
By contrast if I open Visual Studio 2019 Developer Command Prompt as you can see from the image bellow: v16.9.4 I'm able to execute commands on it.
And this is what happens with the PowerShell
Note: I know there's the settings options but I haven't modified anything yet there.
Am I missing somthing or someone else could point me in the right direction to make it work?
I have solved or found a workaround.
In my initial post, I did mention that I knew that there was a settings option but I haven't done anything there ... yet.
Finally, I solved going in that direction.
So, just in case someone else faces the same or similar situation.
My built-in Developer PowerShell (inside Visual studio) is configured as follows:
shell location: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -NoExit -Command "& { Import-Module $env:VSAPPIDDIR\..\Tools\Microsoft.VisualStudio.DevShell.dll}; Enter-VsDevShell -SkipAutomaticLocation -SetDefaultWindowTitle -InstallPath $env:VSAPPIDDIR\..\..\
So, I created a new Developer PowerShell settings called: "Sebas PowerShell" (quite original 🤣) and with the following settings (fewer arguments):
shell location: same location pointing to powershell.exe
Arguments: -NoExit
Like this, it works perfectly fine.
So, I guess it might be related to DevShell.dll or to the other arguments.
In any case, now I can use the Developer PowerShell inside Visual Studio 😀
I know this is a bit late, but I have found that if you have a project selected in Solution Explorer and then choose Open In Terminal, it works fine. If you have any other node selected, the Powershell window opens, but you can't type anything.
No need to create new settings.
Makes sense I suppose, as the point of the terminal is to run commands related to a specific project.
Hope that helps.

Visual Studio Code - Ctrl+Backspace not working in Integrated Terminal

In the terminal (PowerShell) in Visual Studio Code, I'm trying to hit Ctrl+Backspace to delete last word, but it just adds ^W to end of the line, any ideas how to fix this? It works fine outside Visual Studio Code in PowerShell.
ctrl+backspace is somehow mapped to ctrl+w in vscode integrated terminal (possibly a bug) and now we need to set ctrl+w binding to delete the word explicitly. weird right?
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
Note that this'll work for the current terminal session only.
To make this behaviour persistent, you can set it in profile Microsoft.PowerShell_profile.ps1 file. Create the file if it doesn't exist in your powershell version folder.
C:\Program Files\PowerShell\6\Microsoft.PowerShell_profile.ps1
write at the top
if ($env:TERM_PROGRAM -eq "vscode") {
Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
}
See more: Power up your PowerShell
Keybinding references:
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/Get-PSReadLineKeyHandler?view=powershell-5.0
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/set-psreadlinekeyhandler?view=powershell-5.0
Based on the latest comment https://github.com/microsoft/vscode/issues/68167 I have modified JerryGoyal's answer so we don't have to modify bindings:
Put the following at the top of your Microsoft.PowerShell_profile.ps1 config file (type $profile in the terminal to find it, you might have to create one if it doesn't exist already)
if ($env:TERM_PROGRAM -eq "vscode") {
Set-PSReadLineOption -EditMode Emacs
}
This works for me (vscode 1.43)
It was showing ^W when I pressed Ctrl+Backspace.
Just run this command in the vscode console
Set-PSReadLineOption -EditMode Emacs
NOW IT WORKS!
Looks like an issue that is being tracked: see workbench.action.terminal.deleteWordLeft Doesn't Work, Outputs ^W.
Works fine for me in git bash terminal but not powershell as of vscode 1.36.
vscode v1.45 made some changes to these terminal commands, like deleteWordLeft. Does Ctrl+Backspace work better for you now?
See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#removal-of-several-prompt-related-commands
VSCode 1.48 (July2020) might help.
Issue 98404 does allow ctrl+backspace to delete entire word in cmd.exe, which could work for a powershell session too.
See PR 98494:
Before (when it was not working):
After (working):
Check you keybindings in your settings to be sure it is still set.
I have had some oddities with keybindings getting removed / changed when adding a new extension or an update. You may just need to add it back.
Key Bindings for Visual Studio Code
Of course VSCode and PowerShell are two different environments. If you split your terminal window (I do this all the time for my own work use case), you will end up with the VSChost and the standard consolehost and you'll see that though you are in VSCode, they behave differently.
If you have not done so, you may want to customize you VSCode profile which is what the integrated console will read, where as the consolehost will read your PowerShell console profile not you ISE profile.
To add to JerryGoyal answer:
If you have difficulties finding profile folder and/or making it works. Here's what helped me.
I created folder c:\Users\YOUR_USER_NAME\Documents\WindowsPowerShell\
Put Microsoft.PowerShell_profile.ps1 there
Powershell than tells you about security problems. You have to allow this by running powershell as admin.
Than type Set-ExecutionPolicy RemoteSigned.
Answer Y(yes). This is obviously at your own risk!
Add this to keybindings.json in vs code
{
"key": "ctrl+backspace",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": { "text": "\u0017" }
},

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.

Can I get intellisense in powershell?

Edit: Anyone coming to the question now. Please look at the dates. This is a very, very, old question from the first version of PowerShell. Everything is now different
Just starting out with PowerShell, I would love to have intellisense support for writing PowerShell scripts. Tab-completion works great so you would think it would exist somewhere, but the only thing I can find an article from 2007 - hardly up to date.
Is there an extension somewhere that gives you this ability?
How about an editor?
Try this -
http://powergui.org/index.jspa
This is a good editor with intellisense
The Windows PowerShell ISE which is installed with later versions of PowerShell has got built-in intellisense.
Also Visual Studio Code with the PowerShell extension is another option
And ISE Steroids if you want to stay with ISE
But seems direction is VS Code, especially with Core
Have a look on PowerTab.
Also PowerShell Plus (commercial). Or you can wait for PowerShell 2.0 and hopefully get Graphical Windows PowerShell.
PowerSE is a free PowerShell Editor that includes Intellisense (PowerShell, WMI, and .NET)
Features:
Includes Auto-Script creation feature - execute a cmdlet, look at the results in a grid view, select and sort columns, then tell it to generate the PowerShell for you.
Community button to search TechNet and PoshCode for samples.
Debug features such as breakpoints and stepping through code.
Watch window to drill into PowerShell variables.
Context sensitive help.
Imbedded console window with command recorder.
Try visual studio code with powershell extension. It works better than Windows PowerShell ISE for me.
PSReadline now has intellisense right in the console based on the command history. https://devblogs.microsoft.com/powershell/announcing-psreadline-2-1-with-predictive-intellisense/
To enable in powershell 7:
Set-PSReadLineOption -PredictionSource History
You can also get that version of psreadline in powershell 5.1.
Install-Module PSReadLine -RequiredVersion 2.1.0
I think it is the best way that you write TabExpansion.
There are no Autocomplteion tools for posh, like C#'s IntelliSence.
They can't get even $_'s properties even if you use just a standard Cmdlet.
PowerShell ISE v3 has Intellisense
http://www.microsoft.com/download/en/details.aspx?id=27548