I would like to include a few Powershell customizations that only occur when running inside of VSCode.
When inside of ISE or Package Management Console (inside Vis
VSCode sets the TERM_PROGRAM
environment variable to vscode
in its integrated terminal, so you can use the following test, which works whether or not the PowerShell extension is installed:
$runningInVsCode = $env:TERM_PROGRAM -eq 'vscode'
You could check if VSCode-specific environment variables exist:
if((Test-Path env:\VSCODE_PID) -or ($env:TERM_PROGRAM -eq 'vscode')){
# Running from Vistual Studio Code
}
See also Visual Studio Code $psise equivalent
You may check for $psISE, and if it does not exist, try $context = [Microsoft.Powershell.EditorServices.Extensions.EditorContext]$psEditor.GetEditorContext()
but be aware, this will throw in ISE.
I use this snippet in a lot of my scripts, so I can always reference "$root".
# Makes debugging from ISE easier.
if ($PSScriptRoot -eq "")
{
if ($psISE)
{
$root = Split-Path -Parent $psISE.CurrentFile.FullPath
}
else
{
$context = $psEditor.GetEditorContext()
$root = Split-Path -Parent $context.CurrentFile.Path
}
}
else
{
$root = $PSScriptRoot
}
You can try to check you have VSCode context. The simplest way is to test current VSCode process ID.
if ($Env:VSCODE_PID) { }
And the ISE has own profile (https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/).