Friday, March 14, 2014

PowerShell Tips: Change The Foreground Colour of PowerShell console using .net and PowerShell. and ,Happy Holi

 

Quote of the day Start where you are. Use what you have.  Do what you can. –Arthur Ashe

 

So, it’s nearly weekend.

 

On Monday we have a HOLI festival in India. The festival of colours.

 

Wishing you a very Happy Holi, , May, Your life, be colourful with the colours of joy, fun , happiness and love.

 

That’s all? , arrrrrrrr!!!

 

Let’ me wish you in a PowerShell way.

 

14-03-2014 19-27-10

 

Let’s learn how to change the foreground colour of Windows PowerShell Console.

There are two ways to change the foreground colours of the Console using code, {I know these two ways only for now, the third once is to, go to the properties off Powershell.exe, click on Colours and choose the colour.}.

1.    The PowerShell way.

2.    The .Net way

 

In PowerShell way, you can use $Host.UI.RawUI  and use ForegroundColour properties to change the text colour of the console.

$Shell = $Host.UI.RawUI

$Shell.ForegroundColor = "Green"

 

14-03-2014 20-38-54

 

 

And In our .Net way, you can use  [System.Console]::ForegroundColor  class

  to set the foreground colour.

[System.Console]::ForegroundColor = “Magenta”

 

14-03-2014 20-40-25

 

J

14-03-2014 20-40-57

 

Cool and lovely isn’t?

 

That’s all for now., I hope you liked this video.

 

Happy Holi. Enjoy it.

 

And,,,, this is the code of the happy Holi  script.

 

$myColours = "Green","Red","Blue","Yellow","Cyan","Magenta", "White"

 

foreach ( $colour in $myColours ) {

    [System.Console]::ForegroundColor = $colour

    Write-Output ">===> Happy Holi!!!'May your life be colourful  with the colors of joy, Fun, Happiness, Friendship and Love.., "

 

 

 

}

 

 

clip_image007

With best wishes.

Aman Dhally

 

If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

 

 

 

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.