• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

westerdale.blog

A SharePoint Consultant's Journey, On The Road to Collaboration

  • Home
  • Developer
  • Office 365
    • SharePoint
    • Governance
    • Roadmaps
      • SharePoint Roadmap
      • Microsoft Teams Roadmap
      • OneDrive for Business Roadmap
  • PowerPlatform
  • Keeping Fit
    • Cycling
      • Walsgrave rides
      • Sa Calobra 2020
  • About
    • Contact
    • Experience & Skills
You are here: Home / Developer / Enabling the PowerShell ISE Experience on VSCode

Enabling the PowerShell ISE Experience on VSCode

10th April 2019 by Daniel Westerdale Leave a Comment

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 VS Code 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 Core 7 Support

Update 25/03/2020: how to configure the VSCode PowerShell Extension for PowerShell 7

Read more

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 based analysis provided by the PowerShell Script Analyser
  • F8: to run a selection of highlighted PowerShell script
  • Ctrl + F1: to launch online help for the symbol under the cursor

One word of caution on the syntax highlighting support: when comparing the PowerShell ISE, you cannot have the same pop-up dialog when you hit Ctrl + Space in the terminal window, to show object properties or Cmdlet arguments. This is because of a limitation in VS Code. You can however, fallback on the PSReadline‘s “Menu” completion. The next section covers what this means in practice.


PSReadline

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 latest PowerShell Preview extension to VSCode . It works with PowerShell 5.1 and up. Note, If you already have the stable PowerShell extension (1.x.x) , then you will first need to disable this so that you don’t run both versions of the same extension.

You will also to edit your user settings:

Note, if you follow this path you are presented with the above link to edit the PowerShell User settings VSCode. In which case you must ensure all file paths have double backslashes:(‘\\’). Alternatively, you can open the settings file as shown below without needing the backlashes.

Edit User Settings.json

Notepad %APPDATA%\Code\User\settings.json

Then add the following line to enable PSReadline via a feature flag.

Edit Your Personal VSCode Profile Settings

Whilst in the VS Code terminal you will need to edit your VS Code specific profile :

$profile
C:\Users\[User}\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1
Notepad $profile

Or if you prefer, to create the file if it doesn’t exist, then open it in VS Code.

New-EditorFile $profile

Note the above profile is only active when working with PowerShell in VS Code . Should you go back to work in the ISE then you will require the PowerShell ISE specific profile .

Then add the short key mappings:

Next, you will need to restart VS Code or execute the command below, to reload the workbench window, for above changes to take affect.

Open the command palette ( Ctrl + Shift + P )

Reload Window

To test, you can set a 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

Configure PowerShell 7 Support

On March 7th 2020 the team announced a major release of the extension (2020.3.0) which supports PowerShell 7 and ISE Compatibility mode.

PowerShell Core, is both open source and cross-platform ( Windows, MacOS and Linux).  Furthermore, PowerShell 7 is based on .NET Core 3.1, whereas Windows PowerShell 5.x  is based on the .NET Framework. Given, that PowerShell core is fairly new there will be missing cmdlets and modules. Therefore, you will want have both versions installed and to easily switch between them. Here are the installation steps that will help you do this:

  1. Install PowerShell 7

    Follow the steps in: One-liner to install or update PowerShell 7 on Windows 10

  2. Install the Shell Launcher VS Code extension

    Install and configure the Shell Launcher ,as described in Configure Visual Studio Code to run PowerShell for Windows and PowerShell Core Simultaneously Note, it might take a number of attempts to find the free Keyboard binding for the launcher. I ended up with this :
    { “key”: ctrl + shift + #
    “command”: “shellLauncher.launch”} 

  3. Edit Settings.json to Configure the Desired Shell Launcher Shells

    Open settings.json and add both PowerShell Core 7 and Windows PowerShell 5.1 shell configs ( settings.json example below this instruction block.).  Now, switching between both versions of PowerShell using the Shell Launcher will be reflected in both the editor pane and terminal windows. Note, be aware the PowerShell Core 7 installation may remove any previous PowerShell Core 6 installations .

  4. (Optionally) Install the Settings Sync VS Code Extension

    Install the Settings Sync  to enable backup and restore (download) of VS Code configuration files via your GitHub account: Settings File, Keybinding file, Launch file, Snippets folder, VSCode Extensions & configurations & Workspaces folder.
    You can backup or download a the set of configuration files  with these keyboard shortcuts:
    Upload Key : Shift + Alt + U
    Download Key : Shift + Alt + D

Test Out Your Chosen Keyboard Binding

You can use your chosen keyboard binding to easily switch between PowerShell versions
Switching to ISE Mode

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.

Filed Under: Developer Tagged With: PowerShell Core, VSCode

About Daniel Westerdale

Daniel Westerdale is a freelance SharePoint and Office 365 Consultant, helping both private and public sector clients get the most out of their investment in Microsoft's collaboration technologies.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • GitHub
  • LinkedIn
  • RSS
  • Twitter

Daniel Westerdale

Daniel Westerdale is a freelance SharePoint and Office 365 Consultant, helping both private and public sector clients get the most out of their investment in Microsoft's collaboration technologies.

About…

Categories

Latest Posts

  • Set Up App-Only Access To Your Tenant to solve (401) Unathorized Errors 26th June 2020
  • Enable MFA for Users with Office 365 E3 and E5 Licenses 8th June 2020
  • Protected: GITHub Cheat sheet 12th January 2020
  • Cycle Live Nottingham 2019: 75 Miles 30th June 2019
  • Walsgrave Rides 2019-2020 13th May 2019

Copyright © 2021 — Westerdale Solutions Ltd • All rights reserved. • Privacy Policy •Built on: Genesis Framework •