PowerShell script outputs colored text

When writing a PowerShell script, the text output by echo is white by default, and the length of the log information output is somewhat confused.

Output Color Text

The echo in PowerShell is the alias of the native method Write Host. In order to make it more convenient for people who have experience in shell commands to use it, Microsoft has made a set of alias encapsulation for its native methods that emulates Unix commands.

In order to set the text color, we can directly use Write Host. Write Host can set the output color as follows:

 Write-Host "Red on white text. " -ForegroundColor red -BackgroundColor white

Among them, ForegroundColor The parameter is the foreground color, that is, the text color, and BackgroundColor Is the background color.

effect

Take an example of the automatic packaging process of Electron written earlier, green text interspersed in the middle can easily distinguish the packaging progress.

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/6512.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*