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

82 Upvotes

52 comments sorted by

View all comments

2

u/Over_Dingo 13d ago

I have shift + alt + enter for code formatting

1

u/Incrediblecodeman 12d ago

What that’s cool so you like highlight taect then press shift alt enter and it formats it with colors like visual studio ?

(We paste scripts in vscode then copy again and then paste in one note so it’s pretty lol )

You remind me of auto hotkey tho. Can you explain?

1

u/Over_Dingo 12d ago
Set-PSReadLineKeyHandler -Chord 'Shift+Alt+Enter' -ScriptBlock {
$line = $null; $cursor = $null 
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
if ($line) {
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert((Invoke-Formatter $line))
}
}

It requires PSScriptAnalyzer module. What's funny is that reddit removes indentation when pasting code.

1

u/Incrediblecodeman 12d ago

lol just screenshot I can feed to ChatGPT to get copy and paste.

Just realized we can’t post image haha I think instagram or something.

But I almost want the opposite to make a one liner (sometimes I notice it copies it upside down and doesn’t run!!

1

u/Over_Dingo 12d ago

Have you tried it?

1

u/Incrediblecodeman 12d ago

Ya a script collapser . Make this script a one liner. It’s just be a bunch of ;;;; lol cool I haven’t no. But ChatGPT can do what ever we want right now thanks for talking these are the things that get me into IT

1

u/Over_Dingo 11d ago

Well, collapsing is mostly replacing newlines with ';'. But did you try my psreadline setting

1

u/Incrediblecodeman 11d ago

Will try thanks hmmm

1

u/Incrediblecodeman 11d ago

Dude it’s hard as fuck! It mentioned that here strings are an issue. I’ll let you know !