Do you feel that PowerShell just isn’t as cool as you? Do you wish that you could make it cool like yourself? Me too!
So how do we do this? By modifying the default PowerShell profile. The default profile is just a standard ps1 file that runs each time you launch a PowerShell Console. A quick search online and you’ll find there are five different locations this profile can live -crazy huh. There’s All Users, ISE, Personal. The best one to modify I found is the one that lives in your WindowsPowerShell folder in your User Profile path (C:\Users\{Username}\Documents\WindowsPowerShell\). By default the file probably doesn’t exist but you can easily create it by making a file called profile.ps1 and placing in this path.
One of the quickest ways to enhance the PowerShell prompt is to add a little ASCII art to PowerShell when the console is first loaded. I originally got the idea from a session I went to by Chris Wahl. Chris used a simple one line piece of ACSII art showing his venting of emotion flipping a table. You can find a lot of this art at http://www.copypastatroll.com/one-line-ascii-art/. The issue I found was using the extended ASCII character set was difficult to use. Most of the time it didn’t translate well using Write-Host in PowerShell.
This gave me the idea of using a here-string to create a multi-line string. It opens the door to creating large ACSII art images using the standard character set which makes it much more compatible on-screen. A good starting place for this art is www.chris.com/ascii/
So how can we achieve this? As mentioned above we create a profile.ps1 file in ‘C:\Users\{Username}\Documents\WindowsPowerShell\’. Then paste our art between @” and “@ characters and save it to a variable. In the below example we call it $block.
We can print it out on the screen using Write-Host which also allows us to change the foreground color using -ForegroundColor.
$block = @" . . . . . . . . . + . . . : . .. :. .___---------___. . . . . :.:. _".^ .^ ^. '.. :"-_. . . : . . .:../: . .^ :.:\. . . :: +. :.:/: . . . . . .:\ . : . . _ :::/: . ^ . . .:\ .. . . . - : :.:./. . .:\ . . . :..|: . . ^. .:| . . : : ..|| . . . !:| . . . . ::. ::\( . :)/ . . : . : .:.|. ###### .#######::| :.. . :- : .: ::|.####### ..########:| . . . .. . .. :\ ######## :######## :/ . .+ :: : -.:\ ######## . ########.:/ . .+ . . . . :.:\. ####### #######..:/ :: . . . . ::.:..:.\ . . ..:/ . . . .. : -::::.\. | | . .:/ . : . . .-:.":.::.\ ..:/ . -. . . . .: .:::.:.\. .:/ . . . : : ....::_:..:\ ___. :/ . . . .:. .. . .: :.:.:\ :/ + . . : . ::. :.:. .:.|\ .:/| . + . . ...:: ..| --.:| . . . . . . . ... :..:.."( ..)" . . . : . .: ::/ . .::\ "@ Write-Host $block -ForegroundColor Green
We don’t stop here though. There’s a few other things we can do. Most of my code lives in a specific folder. So we can modify the default folder path that PowerShell opens to by added the below code to the bottom of the profile.ps1 file. The next time PowerShell opens its defaults to this path.
Set-Location 'C:\Folder\Code'
Let’s now fix that crappy Title Bar and change it to something more inspirational.
$host.ui.RawUI.WindowTitle = 'Know yourself and you will win all battles.'
Finally let’s fix that bland prompt and give it a little color.
function Prompt { $promptString = "PS " + $(Get-Location) + ">" Write-Host $promptString -NoNewline -ForegroundColor Cyan return " " }
Let’s see what our PowerShell Console now looks like. Much better! We can now show people how cool we really are. When people see our console they will tremble in our PowerShell skillz 😛
Putting it all together, let’s see what the code looks like.
$block = @" . . . . . . . . . + . . . : . .. :. .___---------___. . . . . :.:. _".^ .^ ^. '.. :"-_. . . : . . .:../: . .^ :.:\. . . :: +. :.:/: . . . . . .:\ . : . . _ :::/: . ^ . . .:\ .. . . . - : :.:./. . .:\ . . . :..|: . . ^. .:| . . : : ..|| . . . !:| . . . . ::. ::\( . :)/ . . : . : .:.|. ###### .#######::| :.. . :- : .: ::|.####### ..########:| . . . .. . .. :\ ######## :######## :/ . .+ :: : -.:\ ######## . ########.:/ . .+ . . . . :.:\. ####### #######..:/ :: . . . . ::.:..:.\ . . ..:/ . . . .. : -::::.\. | | . .:/ . : . . .-:.":.::.\ ..:/ . -. . . . .: .:::.:.\. .:/ . . . : : ....::_:..:\ ___. :/ . . . .:. .. . .: :.:.:\ :/ + . . : . ::. :.:. .:.|\ .:/| . + . . ...:: ..| --.:| . . . . . . . ... :..:.."( ..)" . . . : . .: ::/ . .::\ "@ Write-Host $block -ForegroundColor Green Set-Location 'C:\Folder\Code' $host.ui.RawUI.WindowTitle = 'Know yourself and you will win all battles.' function Prompt { $promptString = "PS " + $(Get-Location) + ">" Write-Host $promptString -NoNewline -ForegroundColor cyan return " " }
Pretty simple right. A few small additions and we’ve brought our console to life. When all is said and done though, none of this will actually make us better scripters. But when your spending all day at a console prompt why not bring a little of you into it? I’d love to know what you do?