Did you know.. Customising your PowerShell Window

powershell2xa4Some time ago i read a blog or forum entry that mentioned being able to customise your PowerShell Window with alternate background colours much like you could with the old Command Prompt. It was one of those thing i thought was cool but would look at later. So today i decided to get this done.  I did sit and think about whether or not to even write this up as a post, given i am not really coming up with anything new and just linking to what other people have done, but then i thought, well without people doing that the internet would be a much smaller place.

So, first i did a search for customising your PowerShell profile.

The first link i hit on was from How-To-Geek, and i pretty much followed that through and got the results as advertised, demonstrating how to take your PoSh window from a boring Blue, to a dynamic Grey.

How To Geek 1

I did this and played with various Colour settings, but what i also did was load up the PS1 in PowerShell ISE rather than notepad.

So then, what i really wanted was to separate Elevated and Non Elevated Sessions. So i did a quick search and i didn’t hit upon the answer immediately.

That is not to say it is not out there, step by step and with similar results – just that i didn’t find it.

I have used a bit of code in scripts to check for elevation, and i wondered if that would apply in my profile, good news is that it does.

The code in question is this,

[Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"

Add that to an ‘If’ statement and code block, and you get the following.

Shell Customisation

if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator" ))
    $shell.WindowTitle = "ADMIN: Roberts PowerShell"
    $shell.BackgroundColor = "DarkRed"
    $shell.ForegroundColor = "White"

If the Session is found to be elevated, then we modify the values contained within the curly brackets, changing the Window Title, the Background and Foreground Colours.

Which produces this result.

Shell Customisation 2

It also helps to distinguish multiple windows from the taskbar.

Shell Customisation 3

Hopefully this gives enough of a pointer on where to look for resources and also gets you thinking on just what is possible to do in your Profile.


Useful Links:






About Robert Pearman
Robert Pearman is a UK based Small Business Server enthusiast. He has been working within the SMB IT Industry for what feels like forever. Robert likes Piña colada and taking walks in the rain, on occasion he also enjoys writing about Small Business Technology like Windows Server Essentials or more recently writing PowerShell Scripts. If you're in trouble, and you can find him, maybe you can ask him a question.

Leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: