brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: $PROFILE is the startup file of your PowerShell terminal

Terminal
~/tips/tip-terminal-powershell-profile

New-Item -ItemType File -Path $PROFILE -Force

Shows where PowerShell keeps its startup script and how to create it safely.

Aliases, functions and key bindings you set in PowerShell vanish when the window closes. They last when you put them in your profile, and $PROFILE knows where that file lives.

PowerShell doesn’t create the file for you. This makes it only if it is missing, so it never overwrites one you already have:

if (!(Test-Path -Path $PROFILE)) {
  New-Item -ItemType File -Path $PROFILE -Force
}
notepad $PROFILE

Add whatever you want in every session, for example:

Set-Alias -Name ll -Value Get-ChildItem
function repo { Set-Location $HOME\src }

Save, then open a new PowerShell window to load it.

$PROFILE on its own points at the profile for the current user in the current host. There are four in total, and this shows all their paths:

$PROFILE | Select-Object *

Shared things belong in $PROFILE.CurrentUserAllHosts, in my view, so the same aliases also load in the VS Code terminal, which has a host profile of its own.

If nothing happens at startup, look at the execution policy. Under Restricted, the default on Windows client machines, no scripts run, profiles included. Also note that Windows PowerShell 5.1 and PowerShell 7 use different folders, so a profile made in one is not read by the other. And pwsh -NoProfile starts a clean session when your profile itself is the problem.

Further reading: about_Profiles (Microsoft Learn)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link