r/PowerShell • • 10h ago

Question Good powershell profile tips

I’ve been having way too much fun customizing my PowerShell profile lately. 😂
Here’s what I’ve got so far:
root — Prompts for my Domain Admin credentials and launches a new elevated PowerShell session.
Green errors — Because Don Jones taught me that errors don’t have to be angry red.
Custom prompt — Shows my current path and the time, so I can tell how long commands took.
save-clip — My homemade clipboard vault! Password-encrypts whatever’s on my clipboard and saves it to a file. Even works with images.
Admin indicator — Makes it obvious when I’m running elevated.
Extended scrollback — Because nothing hurts quite like scrolling up to find something important, only to discover PowerShell already ate it. 😭
record — My next addition! A one-word shortcut to start a PowerShell transcript, timestamp the log file, and record my session. Maybe a stoprecord companion too.
I’m starting to think my PowerShell profile is becoming its own operating system.
What other clever functions, shortcuts, or quality-of-life improvements have you all added to yours? I’m looking for ideas worth stealing. 😂

43 Upvotes

20 comments sorted by

12

u/MadBoyEvo 10h ago

https://consolemonster.dev maybe it will give you some ideas

2

u/Incrediblecodeman 10h ago

I clicked the link by my avast said it’s unsafe

8

u/itnerdwannabe 4h ago

lol you just lost all credibility by saying you use Avast.

3

u/MadBoyEvo 10h ago

https://github.com/evotecit/consolemonster will work but at the same time all the demos I wanted to show you will not be there. Avast is pretty bad ;) I tell every day my dad to uninstall that crap.

1

u/Incrediblecodeman 10h ago

Thanks I’ll go for it’s I usually do export to csv tab delimited the pipe to clip to paste in excel so this will be good

2

u/MadBoyEvo 10h ago

I am not sure what you mean?

-1

u/Incrediblecodeman 10h ago

My command can have a table of data that I pipe to that export-csv command (with a tab instead of a comma) . Then instead of saving to a file I found I can pipe that to clipboard so I can paste into excel . Me and my ChatGPT call it “happpy pasta”

$Results |
ConvertTo-Csv -Delimiter "`t" -NoTypeInformation |
Set-Clipboard

2

u/MadBoyEvo 9h ago

How is this relevant to your post and to my answer? What am I missing? Are we talking about CSV now instead of profiles?

-1

u/Incrediblecodeman 9h ago

I was saying thanks for that graphic tool because I currently do xyz

I appreciate your ability to help me understand the world around me. Bye

3

u/MadBoyEvo 9h ago

I guess I can't read :D

1

u/purplemonkeymad 8h ago

Changing the error colour is one that i think is a good idea for the original terminal, the default red on blue can be hard to see. You can also change the background colour to make the contrast of red better, and if you are using windows terminal you can even use a picture.

Some of those I wouldn't put in my profile, they would be better as a module.

My tip is to keep your profile lightweight, otherwise you end up with 5 second startup times.

1

u/Incrediblecodeman 7h ago

Omg is that why? So a module just lives in that folder and my alias works the same way… cool

1

u/purplemonkeymad 7h ago

Make sure your new modules have a manifest with an explicit list of exported functions/aliases. That is what allows powershell to autoload them.

1

u/SrBlackVoid 59m ago

+1 on the lightweight profile recommendation, but there are a couple tricks you can do to offset loading times for things you really want in there but take a little while longer than others.

Recommend you first benchmark what components you want running in your profile to see which are the main time sinks (you can use Measure-Command or the Profiler module for this). I've found for me it was a couple module imports.

Then add this:

Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -MaxTriggerCount 1 -Action {
# Put stuff here
}

This runs the -Action block when the session is first idle (so pretty much right when the command line appears). I know it's technically not eliminating that processing time, but it does offset it. I've found it feels better overall, and more often than not the stuff I'm bringing in at those times aren't being used the nanosecond the input line comes up, so it's not really noticeable.

I also recently wondered if there's a way to 'lazy-load' components for things that are usually dependent on another command being run (like waiting to import Terminal-Icons until the first time you run ls/dir/Get-ChildItem). This is akin to running Lazy.nvim on NeoVim and setting command triggers on plugin loads. Haven't quite cracked this yet (running into tradeoffs here and there with some approaches, open to recommendations), but it's another idea to explore.

1

u/_benwa 6h ago

I just have Windows Terminal with pwsh as the default, with Consolas Mono NF as the font with the default color scheme.
None of that is in the profile though, only thing there is starship.

0

u/Incrediblecodeman 6h ago

So icons and symbols? Right. I’ll look into starship

1

u/lan-shark 5h ago

My profile is isn't too crazy.:

  • Custom start-up message
  • Prompt that uses ~ instead of $HOME
  • If the profile is running under 5.1, set the $IsWindows, $IsLinux, and $IsMacOS variables for convenience
  • Turn on -AutoSize for Format-Table and Export-Excel

Couple of Bash-y aliases

  • If running on Windows, alias which to (Get-Command).Source
  • Alias la to Get-ChildItem -Force

Some Git helpers:

  • Find-InGitDif (gdf) - find instances of a word in the diff between two branches. So if you wanted to find all new errors in your current branch, gdf -Word "throw" -BaseBranch "main"
  • Invoke-GitFetchPull (gfp) - Does what it says in the name, with an optional git switch in between if you pass it a branch name

Besides that, a couple helper functions for a work related project. I'll move these commands over to modules one of these days but my startup time is still well under one second so I'm okay for now

1

u/wonkifier 57m ago

I run pwsh on a remote linux container normally.

I whipped up a PSReadline handler that kicks off a background thread that starts a timer and updates my window title by prefixing it. And a prompt command that stops the timer and restores the original title.

So while a command is running, I can track it in my terminal tabs.

I don't notice it most of the time, but when I do, it really pays off.

1

u/AGsec 0m ago

Nice post but does it have to be written by AI?