Changing the Location of PowerShell Profile Scripts

A PowerShell profile is an init script that is executed when the shell starts. PowerShell searches for profile scripts in hard-coded locations. This article explains how to move profile scripts to any directory of your choice.

Where are Profile Scripts Located?

As documented here, PowerShell has per-machine in addition to per-user profile scripts. We’ll ignore the former and focus on the latter.

User Profile Scripts

Per-user PowerShell profile scripts are stored in the Windows user profile. The path and name depend on the PowerShell version as well as the PowerShell host (e.g., Windows Terminal, VS Code). Here’s a quick overview:

PowerShell versionPowerShell hostPathFile name
Windows PowerShell (5.x)all hosts%USERPROFILE%\Documents\WindowsPowerShellprofile.ps1
PowerShell (7.x)all hosts%USERPROFILE%\Documents\PowerShellprofile.ps1
Windows PowerShell (5.x)console host, Terminal%USERPROFILE%\Documents\WindowsPowerShellMicrosoft.PowerShell_profile.ps1
PowerShell (7.x)console host, Terminal%USERPROFILE%\Documents\PowerShellMicrosoft.PowerShell_profile.ps1
Windows PowerShell (5.x)VS Code%USERPROFILE%\Documents\WindowsPowerShellMicrosoft.VSCode_profile.ps1
PowerShell (7.x)VS Code%USERPROFILE%\Documents\PowerShellMicrosoft.VSCode_profile.ps1

Changing the Location of PowerShell Profile Scripts

The symlink technique I used for Windows Store apps like Windows Terminal doesn’t work well with PowerShell because it breaks dot-sourcing (including additional scripts from a path relative to the symlink target). We can use dot-sourcing as a simple alternative, though.

Source

Using the table above, determine the path and file name of the profile script whose location you want to change. For the PowerShell 7 all hosts script, for example, that would be:

%USERPROFILE%\Documents\PowerShell\profile.ps1

Create that as a new (empty) file and open it in an editor.

Target

In the above profile script, we place a single instruction to include the actual profile script from the target directory, e.g.:

. 'D:\Data\PowerShell\profile_v7.ps1'

That’s it! We effectively redirected from %USERPROFILE%\Documents\PowerShell\profile.ps1 to D:\Data\PowerShell\profile_v7.ps1.

Comments

Related Posts

Obsidian: Getting Started With the Markdown Note-Taking App

Obsidian: Getting Started With the Markdown Note-Taking App
Ever since the original Microsoft OneNote was discontinued I’ve been on the lookout for my ideal note-taking app. Having settled on Markdown as the perfect file format I’ve tried numerous apps and occasionally blogged about the experience. In my quest to find the app that combines a great UX with elegant esthetics, speed and full keyboard control I’ve recently settled on a combination of Typora and Obsidian - none of which are perfect, but both are satisfying tools to use and they even complement each other. This article explains how to get started with Obsidian.
Applications

Fixing VS Code UI Unresponsiveness Caused by GitHub Copilot Extension

Fixing VS Code UI Unresponsiveness Caused by GitHub Copilot Extension
This article shows a simple solution to a problem that doesn’t seem to be adequately documented: VS Code UI lags, freezes, and delays caused by the GitHub Copilot extension. Problem: VS Code UI Becoming Slow Having worked on a Python project for a while, I noticed that VS Code’s UI was frequently freezing for seconds at a time. This was happening in various places of the UI: the editor itself but also in the GitHub Copilot Chat window. Copilot also seemed to be taking more and more time getting ready to answer, and the extension-host process would fully saturate one CPU core for long periods of time.
Applications

Latest Posts

Beautiful Slide Decks from Markdown: Presenting with Slidev

Beautiful Slide Decks from Markdown: Presenting with Slidev
Would you like to get away from PowerPoint and author slide decks in Markdown? Then Slidev may be just what you’re looking for. It’s a web app for presentations. The fact that it’s geared towards developers shouldn’t put you off. After all, who isn’t a developer these days, with AI? Slidev comes with the beautiful Tahta themes and supports features like syntax highlighting and animations. Export options to PDF and PPTX allow for easy sharing. This article shows how to get started.
Applications