Posted by: Colin Smith
Formatting, Powershell, Scripting
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