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

Thinking Outside the Box with Another PowerShell Prompt

Posted on January 21, 2019January 21, 2019

TThe other day I shared my simple PowerShell prompt function that displayed a few pieces of potentially useful information in a color coded box. Today I have a slight variation that also contains a few improvements. One of the things that I was torn with in my previous version was the prompt itself. I like to have as much room at the prompt as possible to write my PowerShell expression. Showing the date and version number ate up a bit too much space. So I moved the date and time inside the box as a second line.

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!

The Adjustments

In order to get the length of the box properly calculated and to pad the text lines so that everything lines up, I ended up sorting the line lengths to get the longest one.

#get the length of the longest line in the box and uas that to calculate lengths and padding
    $longest = $text1.length, $text2.length | Sort-Object | Select-Object -last 1
    $len = $longest + 2

I also used this value to pad each line with blank spaces.

Write-Host $text2.PadRight($longest, ' ') -NoNewline -ForegroundColor yellow

The Code

The complete function is on Github.

PowerShell Prompts

Here are some examples of the prompt in action.

BoxPrompt2 on Windows PowerShell

BoxPrompt2 on PowerShell Core Linux

BoxPrompt2 on PowerShell Core Windows

If you try this out and modify it, I hope you'll let me know what you came up with. Have a great week.


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

4 thoughts on “Thinking Outside the Box with Another PowerShell Prompt”

  1. Luc FULLENWARTH says:
    January 28, 2019 at 8:58 am

    Hello Jeffery,
    This one is my favorite.
    Any idea how can I change the prompt in a PS Session?
    There is no $profile variable showing where the profile scripts are located.

    1. Jeffery Hicks says:
      January 28, 2019 at 10:32 am

      The easiest way is to simply dot source a script file that contains the prompt function you want. You don’t automatically get profile scripts in a remote session, but as long as you can run scripts, you can dot source any script you want to use as a “profile” script. Including one with a prompt function.

      1. Luc FULLENWARTH says:
        January 31, 2019 at 5:52 am

        Dot sourcing is not a fully automated way to have a prompt, but it works fine and it’s better than altering all users’ prompts by changing the session configuration or using a function each time you want to enter a PSSession. I’ve adopted this method. Thanks!

      2. Jeffery Hicks says:
        January 31, 2019 at 9:22 am

        To add a custom prompt in a remoting session, that’s your only choice I think. Your only other option would be to setup a JEA endpoint for yourself. But that’s a whole lot more work than dot sourcing a script file!

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