Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
17.5k views
in PowerShell by 6 7 9

Is it possible to change the color of the Read-Host in PowerShell? I can easily change the color in Write-Host using "-foregroundcolor" but when tried to use "-foregroundcolor" with Read-Host, It's not worked and print the "-foregroundcolor" in the Read-Host message

change color read host powershell

For example, I need to show the EX: Praveen Kumar with a different color in Read-Host

$name = Read-Host "Please, type your Name, EX: Praveen Kumar"
Please, type your Name, EX: Praveen Kumar

Is there a workaround to use -foregroundcolor with Read-Host in PowerShell?


1 Answer

1 like 0 dislike
by 151 169 345
selected by
 
Best answer

Unfortunately, Read-Host does not have a -ForegroundColor parameter. However, you can use Write-Host with -ForegroundColor as a workaround to use color in Read-Host as below:

Use Color in Read-Host Workaround

$input = $(Write-Host "Please, type your Name" -NoNewLine) + $(Write-Host " EX: Praveen Kumar " -ForegroundColor yellow -NoNewLine; Read-Host) 

Output

Using color with read-host powershell

by 6 7 9
0 0
Very helpful, Mohamed!
If you don’t ask, the answer is always NO!
...