Showing posts with label Dot Net. Show all posts
Showing posts with label Dot Net. Show all posts

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”.

 

 

 

 

Tuesday, August 7, 2012

Powershell Tricks : Use Windows System Sounds in your Powershell Scripts

PowerHi,

In my script i love to add notifications normally i use default beep sound. Few of my script which runs in background while i am working on something else i want to add few more sound notification in to them, So if any error occurred i get aware of them.

I found that windows Dot Net Library have few more extra sound notifications. That library get the notifications sounds those are configured in “Sounds” option in the Control Panel.

Like the Asterisk, Beep sound.

07-08-2012 18-35-32

If you want to add sound notifications in to your scripts, you can use any of the below command listed below in to you script.

[System.Media.SystemSounds]::Asterisk.play()

[System.Media.SystemSounds]::Beep.play()

[System.Media.SystemSounds]::Exclamation.play()

[System.Media.SystemSounds]::Hand.play()

[System.Media.SystemSounds]::Question.play()

try them in your POSH console , you will love then Winking smile 

07-08-2012 18-36-19

Thanks for reading.

Thanks!

Aman Dhally


Buy-More-Twitter-Followers 4fb29548b6adc linkedin