Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Archives
May 12, 2026

Profiling VSCode

In this issue:

  • Profiles
  • PSEditor
    • Workspace
    • Window
      • Show Messages
      • SetStatusBarMessage
    • Context
  • A VSCode Function
  • Summary

The recent newsletters discussing profile protection got me thinking about PowerShell profiles in general. I thought it might be helpful to talk about profiles in Visual Studio Code (VSCode). Although, to be technical, I'm referring to a profile that configures the integrated terminal that is loaded when using the PowerShell extension.

Profiles

This PowerShell session is yet another instance of a hosting application. If you want to have certain variables or PSDrives in the VSCode PowerShell session, you can place that code in the $profile.CurrentUserAllHosts script.

PS C:\> $profile.CurrentUserAllHosts
C:\Users\Jeff\Documents\PowerShell\profile.ps1

Anything in this script will run in any PowerShell 7 session. However, the profile script for the current user in the current host is what I want to look at. In a VSCode PowerShell session, you will see something like this for the $profile variable.

PS C:\> $profile
C:\Users\Jeff\Documents\PowerShell\Microsoft.VSCode_profile.ps1

The file name is hard-coded and will reside in your Documents folder. The file, and possible the PowerShell folder do not exist by default. It is simple enough to create this file from PowerShell.

New-Item $profile -force

You can use this script file to configure your VSCode PowerShell experience. But maybe you didn't realize there was an experience to be had. Let's look at what you might want to put into this profile script.

PSEditor

The integrated PowerShell terminal running in VSCode has a built-in variable called $PSEditor. This exposes the object model for the underlying VSCode Editor Services.

PS C:\> $PSEditor | Format-List

EditorServicesVersion : 4.4.0.0
Workspace             : Microsoft.PowerShell.EditorServices.Extensions.EditorWorkspace
Window                : Microsoft.PowerShell.EditorServices.Extensions.EditorWindow

You can use this object for scripting and automation projects.

Workspace

The Workspace is the VSCode project space that you have opened. Mostly, I open a folder in VSCode and that becomes my workspace.

PS C:\> $psEditor.Workspace

Path                                   Paths
----                                   -----
d:\OneDrive\behind\2026\vscode-profile {d:\OneDrive\behind\2026\vscode-profile}

Look at what we can do with this:

PS C:\> $psEditor.Workspace | Get-Member

   TypeName: Microsoft.PowerShell.EditorServices.Extensions.EditorWorkspace

Name        MemberType Definition
----        ---------- ----------
CloseFile   Method     void CloseFile(string filePath)
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
NewFile     Method     void NewFile(), void NewFile(string content)
OpenFile    Method     void OpenFile(string filePath), void OpenFile(string fil…
SaveFile    Method     void SaveFile(string filePath), void SaveFile(string old…
ToString    Method     string ToString()
Path        Property   string Path {get;}
Paths       Property   string[] Paths {get;}

I can easily open a file from a PowerShell prompt.

$psEditor.Workspace.OpenFile($profile.CurrentUserAllHosts)

It is also easy to create a new file. Yes, you can use the Ctrl+N shortcut. But you can also insert text into the new file and have it open in the editor.

$psEditor.Workspace.NewFile("#requires -version 7.6`n")

Window

Before we get too far, let's look at the other editor item, Window.

PS C:\> $PSEditor.window | Get-Member

   TypeName: Microsoft.PowerShell.EditorServices.Extensions.EditorWindow

Name                   MemberType Definition
----                   ---------- ----------
Equals                 Method     bool Equals(System.Object obj)
GetHashCode            Method     int GetHashCode()
GetType                Method     type GetType()
SetStatusBarMessage    Method     void SetStatusBarMessage(string message), void SetStatusBarMessag…
ShowErrorMessage       Method     void ShowErrorMessage(string message)
ShowInformationMessage Method     void ShowInformationMessage(string message)
ShowWarningMessage     Method     void ShowWarningMessage(string message)
ToString               Method     string ToString()
Terminal               Property   Microsoft.PowerShell.EditorServices.Extensions.EditorTerminal, M…
Want to read the full issue?
GitHub
Bluesky
LinkedIn
Mastodon
jdhitsolutions.github.io
Powered by Buttondown, the easiest way to start and grow your newsletter.