Using a specific PowerShell profile for a Console session, Windows Terminal, PowerShell ISE, or Visual Studio Code

I ran into this somewhere during this week. I wanted to have different PowerShell profiles for other applications. (I don’t need all my functions and scripts being loaded in every PowerShell session or by a Scheduled Task) In this blog post, I will show you how to change your PowerShell profiles and make them specific for an application.

What is a PowerShell profile?

I wrote a blog post about that earlier here, but it’s your startup/login script for every PowerShell session you start. They are stored by default in your Documents folder under the PowerShell (for PowerShell v7) or the WindowsPowerShell (for PowerShell v5) folder. The PowerShell ISE and Visual Studio Code profiles are stored in the WindowsPowerShell folder together with the v5 one.

Specific profiles

PowerShell v5 session (powershell.exe)

For a regular PowerShell v5 session, the profile file ‘Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1‘ is being used. (When running powershell.exe) You can add the following part to your PowerShell profile by running Notepad $profile in a PowerShell v5 session and adding this for specific commands or functions for it:

if (-not $env:wt_SESSION) {
Write-Host 'Hello PowerShell v5 World!' -ForegroundColor Green
}

You can then add PowerShell v5-specific things you use between the two brackets, save the file, and start a new PowerShell v5 session to verify this:

PowerShell v7 session (pwsh.exe)

For a regular PowerShell v7 session, the profile file ‘Documents\PowerShell\Microsoft.PowerShell_profile.ps1‘ is being used. (When running pwsh.exe) You can add the following part to your PowerShell profile by running Notepad $profile in a PowerShell v7 session and adding this for specific commands or functions for it:

if (-not $env:wt_SESSION) {
Write-Host 'Hello PowerShell v7 World!' -ForegroundColor Green
}

You can then add PowerShell v7-specific things you use between the two brackets, save the file, and start a new PowerShell v7 session to verify this:

PowerShell v5 session in Windows Terminal (wt.exe)

For a PowerShell v5 session inside Windows Terminal, the profile file ‘Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1‘ is also used. (When running wt.exe) You can add the following part to your PowerShell profile by running Notepad $profile in a PowerShell v5 session and adding this for specific commands or functions for it:

if ($env:wt_SESSION) {
Write-Host 'Hello PowerShell v5 Windows Terminal World!' -ForegroundColor Green
}

You can then add PowerShell v5-specific things you use between the two brackets, save the file, and start a new Windows Terminal PowerShell v5 session to verify this:

PowerShell v7 session in Windows Terminal (wt.exe)

For a PowerShell v7 session inside Windows Terminal, the profile file ‘Documents\PowerShell\Microsoft.PowerShell_profile.ps1‘ is also used. (When running wt.exe) You can add the following part to your PowerShell profile by running Notepad $profile in a PowerShell v7 session and adding this for specific commands or functions for it:

if ($env:wt_SESSION) {
Write-Host 'Hello PowerShell v7 Windows Terminal World!' -ForegroundColor Green
}

You can then add PowerShell v7-specific things you use between the two brackets, save the file, and start a new Windows Terminal PowerShell v7 session to verify this:

PowerShell ISE (powershell_ise.exe)

The profile file ‘Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1‘ is used for a PowerShell ISE session. (When running powershell_ise.exe) You can add things to your PowerShell ISE profile by running Notepad $profile in a PowerShell ISE session and adding specific commands or functions:

Write-Host 'Hello PowerShell ISE World!' -ForegroundColor Green

You can then add PowerShell ISE (Which is PowerShell v5) particular things you use, save the file, and start a new PowerShell ISE session to verify this:

Visual Studio Code (code.exe)

The profile file ‘Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1‘ is used for a Powershell session in Visual Studio Code. (By running code.exe) You can add things to your PowerShell profile for Visual Studio Code by running Notepad $profile in a Visual Studio Code PowerShell session and adding specific commands or functions:

Write-Host 'Hello PowerShell Visual Studio Code World!' -ForegroundColor Green

You can then add Visual Studio Code particular things you use when editing PowerShell scripts, save the file, and start a new PowerShell Visual Studio Code session to verify this:

Wrapping up

In the chapters above, I showed how to add things to your PowerShell profile specific to a program (Windows Terminal, PowerShell ISE, Visual Studio Code) or a PowerShell v5 or v7 prompt using the $env:wt_SESSION variable, a PowerShell version check or by using a specific profile file. This makes things easier if you have particular modules or functions for a program or version of PowerShell.

2 thoughts on “Using a specific PowerShell profile for a Console session, Windows Terminal, PowerShell ISE, or Visual Studio Code

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.