Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, July 1, 2011 2:00 PM
So I have figured out a good deal about colors, however, one thing I haven't figured out is how to change foreground and/or background colors mid-line on a read-host line.
#colors are:
#Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray
#Blue, Green, Cyan, Red, Magenta, Yellow, White
Write-Host -nonew -fore red "This is--> RED ";Write-Host -fore yellow "This is --> YELLOW"
Write-Host "This is dark green text on a yellow background" -foregroundcolor darkgreen -backgroundcolor yellow
[console]::ForegroundColor = "red"
(get-host).UI.RawUI.Backgroundcolor="Green"
$temp = read-host "This text is red, and it's a read-host."
#reset colors to normal
[console]::ResetColor()
(get-host).UI.RawUI.Backgroundcolor="Black"
read-host "everything should be normal colors now."
Thanks for any help!
All replies (2)
Monday, July 4, 2011 11:36 PM âś…Answered | 1 vote
In script you may using,example:
Write-Host "This text is red," -NoNewline -Fore red
Write-Host " and it's a read-host.:" -NoNewline -Fore Yellow -BackgroundColor gray
$temp = $host.ui.ReadLine()
$temp
Write-Host "This text is red," -NoNewline -Fore red
Write-Host " and it's a read-host.:" -NoNewline -Fore Yellow -BackgroundColor gray
[console]::ForegroundColor = "red"
(get-host).UI.RawUI.Backgroundcolor="Green"
$temp = $host.ui.ReadLine()
$temp
[console]::Resetcolor()
Uploaded with ImageShack.us
Monday, July 4, 2011 11:09 PM
This is not possible with the default PowerShell host.