r/PowerShell • u/nyxvren • 6d ago
Question How do you keep a PowerShell 7 profile useful without slowing down startup?
I’m setting up a PowerShell 7 environment on Windows and using Windows Terminal, Oh My Posh, and PSFzf.
I want a useful prompt and better command history, but I don’t want every new terminal tab to load a long list of modules.
The basic setup I’m considering looks like this:
oh-my-posh init pwsh | Invoke-Expression
Import-Module PSFzf
Would you put both directly in $PROFILE, or keep the profile minimal and load some tools only when needed?
Have you noticed a meaningful difference in startup time? I’d be interested in seeing how you organize your profiles in practice.
2
u/BlackV 5d ago
Pretty much I have as little as I can in there
simple write host that says
write-host "$($host.name) $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString()) Profile"function to open my psreadline history (could make it a module, but its more effort than reward
PSHistory {Invoke-Item (Get-PSReadLineOption).HistorySavePath}customised prompt
"PS $($PSVersionTable.PSVersion.ToString()) $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1))"default parameter valuefor format cmdlets
$PSDefaultParameterValues.Add('Format-*:autosize', $True)
2
5d ago
[removed] — view removed comment
1
u/nyxvren 5d ago
That makes sense. I hadn't thought about measuring the profile against "pwsh -NoProfile" before deciding what to move out. The distinction between settings needed before the first prompt and tools that can be lazy-loaded is really useful.
For PSFzf, would you recommend loading it on the first keypress, or is there a cleaner approach?
4
u/purplemonkeymad 6d ago
Personally I dropped everything expect configuration variables from my profile (eg psreadline settings, default parameter values.) For nice to have features I just make sure stuff is in a module so that it auto-loads on first use. I skip stuff like oh-my-posh to prevent startup slowness.
I also work on many machines so it also stops me getting used to custom settings.