The Multifunctioning DBA

Oct 28 2010   9:58PM GMT

Powershell change color of text

Colin Smith Colin Smith Profile: Colin Smith

I am working on a script that accepts some user inputs and then echos that back to the user for validation. For this I wanted to make the text that the user submitted be in RED so that it would stand out and make it more readable.

I was looking for a way to use this doing echo and echo is an alias to write-output. I was disappointed to find that write-output could not change the color of text. So after some digging I found write-host and what do you know, it has a -forgroundcolor and a -background color option as well as one that was new to me called -nonewline. So below is what I did.

write-host “This is in white” -nonewline; write-host ” and this is in red” -foregroundcolor red -nonewline; write-host ” and now back to white”

Give it a try

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: