A new PowerShell window on a freshly installed Windows 11 machine shows a drive letter, a caret, and little else. No history, no aliases, no opinion about how tables should print. Nothing is broken. The console starts with defaults because the script that would change them does not exist yet. PowerShell calls that script the profile, and it runs once per session before the first prompt appears.

The mechanics fit on a page: four possible file locations, one policy decision, a fixed load order, and a short list of lines worth keeping. The habits around it take longer to build, because the profile is a small program that runs in every window, including the one opened at 2 a.m. to fix something urgent.

Four Profile Files Cover Four Different Scopes

PowerShell resolves the profile by scope, and each scope has two variants, one for every host and one for the current host. A host is the program that embeds the engine: the console, the console inside a code editor, or a custom shell built on the same libraries. The automatic variable $PROFILE points at one of the four files and carries the other three as properties, which makes discovery simple:

  1. $PSHOME\Profile.ps1 runs for every user and every host, needs administrator rights to edit, and is replaced when PowerShell is updated;
  2. $PSHOME\Microsoft.PowerShell_profile.ps1 covers every user but only the console host;
  3. $HOME\Documents\PowerShell\Profile.ps1 covers one account across all hosts, which suits functions that should follow the person rather than the program;
  4. $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 covers one account in one host, needs no elevation, and is the file $PROFILE resolves to.

The folder depends on the engine. Windows PowerShell 5.1 keeps its per-user files under Documents\WindowsPowerShell, PowerShell 7 under Documents\PowerShell. Both engines sit side by side on Windows 11 and share nothing, so an alias added in one is invisible in the other. The host name changes the file name too, and the console inside a code editor registers a different host, which is why its profile lives in the same folder under a different name.

The operating system adds one wrinkle. When the Documents folder is redirected into a synced account folder, $HOME\Documents follows it and the profile travels between machines, which helps until two machines edit the same file.

The Current User File Wins for Everyday Work

The fourth file is the right default for a working administrator. It needs no elevation, survives engine updates that overwrite the machine-wide copies, stays out of other accounts on a shared server, and can be deleted without leaving the machine in a strange state.

Creating it takes one line. New-Item -ItemType File -Path $PROFILE -Force builds the file and any missing folder above it, and the force switch keeps it quiet when the file exists. A guard reads better, though, because it states the intent instead of rewriting a file on every pass.

$PROFILE
Test-Path -LiteralPath $PROFILE

if (-not (Test-Path -LiteralPath $PROFILE)) {
    New-Item -ItemType File -Path $PROFILE -Force | Out-Null
}

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
Get-ExecutionPolicy -List

The policy is where most first attempts stop. A Windows 11 client ships with Restricted, which blocks every script, the profile included, so the window opens with red text and none of the settings. The command above allows local scripts and asks for a signature only on files that came from the internet. The scope is the account, not the machine, and no administrator rights are needed.

Group Policy outranks all of it. The last command lists the scopes in precedence order, and a MachinePolicy or UserPolicy entry at the top means a domain setting is in charge; a per-user change will not hold while it exists. It also helps to remember what the setting is for. It stops scripts from running by accident, and it is not a security boundary, a point Microsoft has made more than once. Administrators who treat it as one are usually caught out by a shortcut or an installer that starts PowerShell with the no profile switch.

Startup Order and the Cost Hidden in Convenience

The four files run in a fixed order: all users all hosts, all users current host, current user all hosts, current user current host. Later files win where definitions clash, so a function in the per-user file can replace one written by the IT department.

Everything in those files runs before the prompt appears, in the global session state, so functions and variables stay visible for the rest of the session. That is the whole trick and also the whole risk. A profile that imports four modules, queries Active Directory, and calls git for a status line adds all of that work to every window, including the one opened to run a single command.

Timing it is easy and rarely done. Run a trivial command several times inside Measure-Command, then repeat with the no profile switch, and compare. The gap is the price of the file, paid on every start. A theme engine, three modules, and a network call can turn an instant window into a slow one, and the cost grows on a laptop that rejoins a corporate network from home.

The usual fix is to let module autoloading work. PowerShell finds commands in modules on the module path and imports a module the first time one of its commands is called, so an explicit import is only needed for side effects, such as a module that replaces the prompt or registers a format file. Hiding a rare import inside a function is the other option: the module loads when the function runs, not when the window opens.

PSReadLine Settings Make the Console Worth Typing In

PSReadLine supplies syntax coloring, history search, and prediction. It ships with both engines, but the build bundled with Windows PowerShell 5.1 is older than the one in PowerShell 7, so a parameter present in one may be missing in the other. The guard below inspects the parameter table instead of trusting a version number.

Set-PSReadLineOption -EditMode Windows
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -BellStyle None
Set-PSReadLineOption -Colors @{ Command = 'Green'; Parameter = 'Cyan'; Error = 'Red' }
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

if ((Get-Command Set-PSReadLineOption).Parameters.ContainsKey('PredictionSource')) {
    Set-PSReadLineOption -PredictionSource History
}

Each line changes one habit. Windows edit mode keeps the familiar shortcuts for selecting text and pasting. Incremental saving writes each command as it is entered, so a session that ends badly still leaves a usable history. The color table maps token types to console colors, which is partly taste and partly contrast on a bright screen. The key handlers turn the arrow keys into a search over history instead of a walk backward through it, and that is the change most people notice first.

Prediction is the newest feature here and the one most likely to be absent. When it is available, history-based prediction suggests a full command in gray as text is typed. Suggestions come from the local history file, so they improve with use and stay with the account.

A Prompt Function Should Show State and Cost Nothing

PowerShell calls a function named prompt whenever it needs a prompt string. The default returns the location and a closing angle bracket. Replacing it is the oldest profile trick, and it is where profiles often go wrong, because the function runs after every command and anything slow inside it is felt constantly.

function prompt {
    $ok = $?
    $here = $ExecutionContext.SessionState.Path.CurrentLocation
    $mark = if ($ok) { '' } else { ' !' }
    "$($here.Path)$mark> "
}

Two details make it dependable. The first statement captures $?, the success flag of the previous command, since every command inside the prompt overwrites it; read it later and it describes the prompt, not the work. The path comes from the session state instead of a cmdlet call, which keeps the prompt fast and preserves the provider path.

The conditional branch is a deliberate limit. A prompt that shows the time, the git branch, the container context, and the battery level looks good in a screenshot and feels heavy in daily use, because each segment costs either a file read or a process launch. Editors solve this with caching and background refresh; a profile script has neither. A short prompt that answers two questions, the directory and the last result, stays useful for years.

Functions Beat Aliases for Anything With Arguments

Aliases are name mappings and nothing more. Set-Alias -Name ll -Value Get-ChildItem saves keystrokes, and arguments still pass through, but an alias cannot add a parameter of its own, cannot check input, and vanishes when the session closes. It can also shadow a command without warning, which is how a habit that felt clever becomes a puzzle three weeks later.

Functions cover the rest. They take typed parameters, document themselves, and chain several cmdlets into one verb that matches the question being asked.

function Get-PortOwner {
    param([int]$Port)
    Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue |
        Select-Object LocalAddress, LocalPort, OwningProcess,
            @{ Name = 'Process'; Expression = { (Get-Process -Id $_.OwningProcess).ProcessName } }
}

The function compresses three cmdlets and a calculated property into one command. The alias that often follows is a convenience and stays optional in a way the function does not.

Size sets the limit. Past a few hundred lines the profile turns into a private module with no version, no tests, and no reuse. The move is mechanical: create a folder under the per-user modules folder, put the functions in a script module there, and let autoloading find it. The profile then holds settings and one import, and the functions can be copied to another machine as a unit.

Testing Changes Without Breaking Every Session

Every edit deserves a test in a window that is already open, because a broken profile does not stop PowerShell from starting. It prints an error, then continues with whatever loaded. Dot-sourcing the file re-runs it in place: . $PROFILE. Then $Error[0] shows what failed, and the prompt, aliases, and colors update without a restart.

$tools = Join-Path $HOME 'tools'
if ((Test-Path $tools) -and (($env:PATH -split ';') -notcontains $tools)) {
    $env:PATH = "$tools;$env:PATH"
}
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'

Idempotence is the point of the membership test. Dot-sourcing the profile five times while editing should leave the same environment as dot-sourcing it once, and without the check each reload would add another copy of the folder to the path. A path that grows on every reload slows command lookup and becomes unreadable in a diagnostic dump.

The default parameter value at the end fixes a Windows PowerShell 5.1 behavior that surprises people moving scripts between engines. In 5.1, the redirect operator and Out-File write UTF-16LE by default, so a log written there looks like binary to tools that expect UTF-8. Setting the encoding once in the profile makes both engines agree, at the cost of a byte order mark that most parsers accept.

Two habits prevent most of the remaining trouble. The first is a clean baseline: start with the no profile switch and compare when something behaves oddly, which separates a profile fault from a system fault in seconds. The second is restraint about scope. Set-StrictMode -Version Latest looks responsible in a profile and then breaks every script in the session that reads a property which does not exist. Settings that alter how other code runs belong in that code.

Version control is worth the small effort. A profile changes slowly and breaks suddenly, and last month's copy has rescued more than one machine. A repository also makes the diff readable before a change reaches a shared image or a colleague's laptop.

The profile rewards a narrow ambition. It should remove the typing that happens every day, show the two facts needed to start a session, and otherwise keep quiet. Anything that touches a network, launches a process, or changes global behavior needs a reason, because it runs thousands of times and gets debugged once, usually under time pressure. A good profile is short, commented where the reason is not obvious, and dull in the way that good infrastructure is dull. Written that way, it turns a blank console into a place where work starts on the first line, and nobody has to think about the file again.