You might well be thinking of replacing the Windows PowerShell Integrated Scripting Environment (ISE) , now that Microsoft has announced they have stopped actively developing it. Indeed, on Episode 160 of the Microsoft 365 Developer Podcast : Dev tools that make IT Pros smarter; Matthew McDermott, MVP (@MatthewMcD) spoke about the productivity gains offered PowerShell language support in Visual Studio Code through the VSCode PowerShell extension .
This inspired me to reach out to Matt and subsequently the PowerShell extension team on GitHub, in order configure the PowerShell support. This post documents the steps needed
PowerShell Language Support
The PowerShell language support includes
- Syntax highlighting
- Code Snippets
- Intellisense for Cmdlets ( both in the code editor and the integrated terminal
- Find references to cmdlets and variables
- Rule abased analsyis provided by the PowerShell Script Analyser
- F8: to run a selection of highlighted PowerShell code
- Ctrl + F1: to launch online help for the symbol under the cursor
One word of caution on the syntax highlighting support, as unfortunately you cannot have the same pop-up dialog when you hit Ctrl + Space, to show object properties or Cmdlet arguments. This is because of a limitation in VSCode. You can however, fallback on the PSReadline‘s “Menu” completion. The next section covers what this means in practice.
PSReadline in the context of VSCode refers to the following new features:
- “Menu” completion is similar to the intellense: select completion with arrow keys but instead uses Ctrl + Space . Note, this is
which is identical to what you get in regular pwsh.exe.
- Ctrl + Arrow keys ,etc (keyboard navigation of the input line)
- Syntax highlighting of input text
- Multi-line text input (writing a function definition in the console across multiple lines)
- Up / Down Arrow history navigation
Eventually, the team will roll out the full PSReadline experience as discussed in Scott Hanselman’s post, identical to a regular console.
Configure PowerShell Preview Exension
To get PSReadline support you will need add the PowerShell Preview (2.0.2) extension to VSCode . it works with PowerShell 5.1 and up. Note, If you already have the stable PowerShell extension (1.12.1) , then you will first need to disable this so that you don’t run both versions of the same extension. You easily enable or disable and installed extension after selecting it in the Extensions:Marketplace.
You will also to edit your user settings:
Then add the following line to enable PSReadline via a feature flag.
Whilst in the VSCode terminal you will need to edit your VSCode specific profile :
$profile C:\Users\[User}\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1 Notepad $profile
Or if you prefer: creates the file if it doesn’t exist and opens it in vscode
Note the above profile is only active when working with PowerShell in VSCode . Should you go back to work in the ISE then you will require the PowerShell ISE specific profile .
Then add the short key mappings:
You will need to restart VSCode or more simply, reload the workbench windows for above changes to take affect.
Open the command palette ( Ctrl + Shift + P )
To test, you can set breakpoint in the debugger and inspect the properties of an object with Ctrl + Space . You should see the PSReadLine experience which is identical to what you get in regular pwsh.exe
Remember the PowerShell Preview is still being worked so should you find and issue you may want to recreate and attach the logs before submitting the issue.