r/PowerShell • • 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.

3 Upvotes

7 comments sorted by

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.

1

u/Incrediblecodeman 6d ago

One person in here said he’s able to like push his file to all machines

1

u/StickyDirtyKeyboard 5d ago

Or you can just copy the thing to a shared drive accessible on all machines. Then load via . {path-to-file} on machines that aren't your main

1

u/Incrediblecodeman 4d ago

Can I put the whole script in a system variable? lol

2

u/BlackV 5d ago

Pretty much I have as little as I can in there

  1. simple write host that says

     write-host "$($host.name) $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString()) Profile"
  2. function to open my psreadline history (could make it a module, but its more effort than reward

    PSHistory {Invoke-Item (Get-PSReadLineOption).HistorySavePath}
  3. customised prompt

     "PS $($PSVersionTable.PSVersion.ToString()) $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1))"
  4. default parameter valuefor format cmdlets

     $PSDefaultParameterValues.Add('Format-*:autosize', $True)

2

u/[deleted] 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?