Customising Windows PowerShell Version 3 Profile

$I will show you how to have a little bit of fun with your PowerShell Version 3 Profile. For those that don’t know, the PowerShell profile is loaded when the PowerShell console is started.

Find the location of your profile by getting the contents of the profile variable:

image

Open notepad and save a .ps1 file in that location.

You can change the colour of the background and text colour using the following:

image

The above is possible in all previous versions of PowerShell. Make sure to run Clear-Host after modifying the properties of the host to see the changes reflected in the console.

You can then welcome the user using the next line (also possible in previous versions of PowerShell)

image

Now for something new. Let’s get the weather where I live in Gladstone QLD using the Invoke-RestMethod cmdlet that is new in PowerShell Version 3 (click the picture to zoom):

image

In the example above, I am using the Yahoo! Weather APIs.

What does it look like when it’s run?

image

I also changed the title just for good measure, see the full source code below:

$Host.UI.RawUI.BackgroundColor = "Black"
$Host.UI.RawUI.ForegroundColor = "Green"
$Host.UI.RawUI.WindowTitle = "Wayne's Windows PowerShell"
Clear-Host
Write-Host "Hi $env:Username"
$WeatherCondition = (Invoke-RestMethod "http://weather.yahooapis.com/forecastrss?w=1102240&u=c").Condition
Write-Host "It's a" $WeatherCondition.Text"day, max temperature will be" $WeatherCondition.Temp

Popular posts from this blog

Get local computer UUID/GUID using Windows Powershell

gPLink and gPOptions

PSLoggedOn Getting Started on Windows Server 2008 R2