Did you know.. Customising your PowerShell Window
September 16, 2014 Leave a comment
Some 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.
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.
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.
It also helps to distinguish multiple windows from the taskbar.
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:
http://www.howtogeek.com/50236/customizing-your-powershell-profile/
http://technet.microsoft.com/library/dn425048.aspx
http://technet.microsoft.com/en-gb/magazine/2008.10.windowspowershell.aspx
http://www.computerperformance.co.uk/powershell/powershell_profile_ps1.htm