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

Configuring the VSCode PowerShell Terminal

Posted on June 9, 2016June 10, 2016

Yesterday I posted my experiences in setting up the latest build of VSCode on how to use a PowerShell terminal session. As I explained, in this particular session I didn't want to run any profile scripts. My reasoning was that this session obviously wasn't the ISE nor was I likely to use the session like I do the traditional console host. But, I also realized there were some tools and settings I would find useful. Obviously I didn't want to manually configure the VSCode PowerShell session every time it started. It needed a profile script.

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!

Since VS Code is simply running PowerShell.exe, there were no new profile options. So I created my own.  I wrote a simple PowerShell script that dot sourced a few items so that I'd have access to tools and functions in this terminal. As well as defining variables that will be unique to this session.

#profile script for VS Code PowerShell session

Write-Host "Configuring VSCode PowerShell Terminal" -ForegroundColor Yellow

#dot source some useful commands and tools
. C:\scripts\Copy-HistoryCommand.ps1
. C:\scripts\Tee-MyObject.ps1
. C:\scripts\jdh-variables.ps1
. C:\scripts\jdh-psdrives.ps1
. C:\scripts\jdh-aliases.ps1
. C:\Scripts\Copy-Command\Copy-Command.ps1

#define some VSCode specific variables for future use.
$InVSCode = $True

This is essentially a stripped down variation of my normal PowerShell profile script. Next, I modified the batch file I'm using to launch PowerShell in VSCode.

::STARTPS.BAT
::This batch file is intended to start a PowerShell session
::as an integrated terminal window in VS Code

@echo off
::Force running the 64bit version of PowerShell
c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -nologo -noexit -noprofile -file c:\scripts\vscode-profile.ps1

I'm telling PowerShell to run a script file and then not exit. Now when I launch PowerShell in VSCode I get a result like this:

VSCode PowerShell Session

I'm looking forward to exploring how I can use VSCode in my daily script developing. There are limitations today, but I know we're just getting started and I'm very interested to see where we end up.


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