The other day I was watching a good intro video from Shane Young on getting started with PowerShell profiles. I use profile scripts extensively, and they can be extremely useful in configuring your PowerShell experience. One element you could add to your profile is a customized PowerShell prompt. Microsoft provides one by default. It creates a simple function called prompt. The best part is that you can define your own function called prompt, and PowerShell will run it every time you hit enter.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
For example, you may want your prompt to also display the PowerShell version.
Function prompt { "[$(($psversiontable.psversion).tostring())]PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; }
You can go ahead and paste this into your PowerShell session. if you want to see the result. The next time you open PowerShell you'll get your original prompt back. Naturally being the PowerShell extremist that I am I went back and updated my "kitchen sink" prompt function. That is, how much stuff can I cram into a prompt? How about this:
I've annotated with callouts some of the key features. The box outline around the system information is color coded based on the amount of free physical memory. 70% or better is green, at 30% it turns yellow otherwise it turns red.
If you'd like to kick this around, the prompt function and a few helper functions are on Github.
To make this a part of your profile, open your profile script and dot source the script file.
Think of this more as a proof of concept or something to "borrow" from. If you have something cool or interesting in your PowerShell prompt I'd love to hear about it.
Nice prompt, never thought to put the path in the top like that. Allows for easy viewing of what you are doing while in deep paths. I do believe I will use some of this, thank you!
Doesn’t look like PowerShell 6 on Windows 10 likes this function. I get data, but the Write-Host commands for the box outline are a bit messed up. I know it won’t work on Linux because of the Get-Cimstance commands.
I should also mention that you may get bad formatting depending on your font selection for your console window. Lucida Console works the best for me for displaying the system information box. Once I changed the font in v6 beta 5 on Windows 10 I got the desired result.
Very nice adjustments. I will definitely borrow something 😉 Thank you!
I like to add current time to the prompt so I have a rough peek at how long each command takes. It is far from perfect as it captures only the end time. The start time is actually previous end time (which may be way off), but it is dead simple, works most of the time and history is visible without any effort.
You could try using this for the timestamp to include the milliseconds.
get-date -format “hh:mm:ss:ffff”