Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Throwing the Kitchen Sink at PowerShell

Posted on August 22, 2017August 22, 2017

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.

Manage and Report Active Directory, Exchange and Microsoft 365 with
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:

everythingprompt1

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.

image

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.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

5 thoughts on “Throwing the Kitchen Sink at PowerShell”

  1. Adam says:
    August 22, 2017 at 12:17 pm

    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!

  2. Jeffery Hicks says:
    August 22, 2017 at 12:56 pm

    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.

  3. Jeffery Hicks says:
    August 22, 2017 at 2:09 pm

    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.

  4. Petr says:
    August 22, 2017 at 2:21 pm

    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.

    1. Jeffery Hicks says:
      August 22, 2017 at 4:44 pm

      You could try using this for the timestamp to include the milliseconds.
      get-date -format “hh:mm:ss:ffff”

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d