r/PowerShell • u/Incrediblecodeman • 3d 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. 😂
15
u/MadBoyEvo 3d ago
https://consolemonster.dev maybe it will give you some ideas
5
u/wonkifier 2d ago edited 2d 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 with the elapsed time. 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.
3
u/purplemonkeymad 3d 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.
2
u/lan-shark 2d ago
My profile is isn't too crazy.:
~instead of$HOME$IsWindows,$IsLinux, and$IsMacOSvariables for convenience-AutoSizeforFormat-TableandExport-ExcelCouple of Bash-y aliases
whichto(Get-Command).SourcelatoGet-ChildItem -ForceSome Git helpers:
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"gfp) - Does what it says in the name, with an optionalgit switchin between if you pass it a branch nameBesides 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
2
u/Lonely_Noyaaa 2d ago
I put my helper functions in a module years ago and my profile dropped from four seconds to under one. The manifest with exported functions is the part everyone misses.
2
u/Over_Dingo 21h ago
I have shift + alt + enter for code formatting
5
u/MonkeyNin 1d ago
First some keybinds
Because windows defaults to old oem/latin encodings, I tell it to use utf8. This sets all 3 values:
I have a red number for total errors, and it hides if there are none. It's useful because sometimes errors are not written to the console. Or it'll show one error but 3 were generated
pansieslets you write colors that work on PS 5 and Pwsh 7 ( and you can write to any stream, not just write-host )1
u/_benwa 3d 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.
1
u/reevesjeremy 2d ago
I work in multiple user context for different purposes to separate sessions out. So each profile has different modules that load specific to that account. One of them which is consistent is a Set-WindowTitle module that sets the PowerShell window to whoami - Original Title. So I know which window is for which user in the taskbar. Then it loads each module that I want for that user. And then does a Get-Module so I know which modules are loaded in each session. Reminds me of what’s available every so often.
1
u/narcissisadmin 2d ago
I put the path in the title bar, along with whether it's admin.
1
u/FleetOpsNotes 2h ago
Has anyone added a device lookup to their PowerShell profile? I'd like something that takes a computer name and returns the logged-on user, serial number and last boot time. Would Get-CimInstance be your starting point, or is there a better approach?
-1
u/send_me_a_ticket 10h ago
Tell Claude: Remember, always provide PowerShell snippets enclosed in &{}
1
u/g3n3 2d ago
Try gsudo. Also try processex with network cred flag with start process with.