Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell Sessions and VS Code

Posted on June 8, 2016

If you do any amount of PowerShell scripting you have most likely heard about Visual Studio Code. This is a free cross-platform light-weight editor from Microsoft. VS Code supports multiple languages and is extensible. I've tried different versions since it was first released but never found a reason to jump from the PowerShell ISE. For my purposes the ISE works just fine plus I've customized it so much that it would be hard to abandon. But there is a new version of VS Code that is at least making it more tempting.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

The May 2016 release of VS Code (v1.2.0) now includes an integrated terminal. You've always been able to launch a CMD or even a PowerShell session but it was completely separate. Now the terminal is integrated into the product.

image

The terminal extension is far from feature complete but definitely a step in the right direction. For example, you can paste into it but you can't copy out of it. There's no F8 or F5 equivalents like there is in the PowerShell ISE. But it is a full PowerShell console. You can do remoting, import modules, even change console colors.

To access the terminal you use the Ctrl+` key combination. I wasn't sure I'd like that combo but at least on my keyboard it is an easy one to make. By default on Windows machines you'll get a CMD session. From there you could start PowerShell. Or you can modify your personal settings. In VS Code go to File - Preference - User Settings. Insert this line:

"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"

It should be inside a set of curly braces. If you have multiple settings, they need to be separated by commas.

Did you notice the sysnative folder reference? If you try to do a directory listing you won't see it. It is a virtual folder in Windows. But this is the trick, especially if you are running an x64 desktop, which I assume most of you are. Because VS Code on Windows is still a 32-bit app, if you used a line this like:

"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",

You would get the 32-bit PowerShell session.

image

That's certainly not what I wanted which is why I'm referencing the SysNative virtual folder.

When the PowerShell session opens, it will run all of your profile scripts. Now, even though there is a VS Code setting to disable PowerShell profiles, it doesn't apply to this terminal as it is a new process. Personally, in VS Code, I didn't want any of my profile scripts to run because I wanted a clean session to test code and commands from VS Code. Since you can't add any parameters to the shell parameter, I devised this work around.

I wrote a simple batch CMD batch file.

::startps.bat
@echo off
c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -nologo -noprofile

I then modified the user settings to launch it.

"terminal.integrated.shell.windows": "c:\\scripts\\startps.bat"

Now I get the PowerShell terminal I want.

image

I'll have more about my experiences with VS Code as a PowerShell development tool. The team realizes there is much more work to do and I look forward to their efforts. In the meantime I'd love to hear about your experiences and impressions.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d