pages

Write-Color.ps1 – Usage Example #1

Write-Color.ps1 usage example showing how to format PowerShell console output with multiple colors for clearer scripts, status messages, and operator-friendly results.

Write-Color is a great function. Check below to see how you can use it to achieve goals.

Please notice this article **contains parts of information **(still useful) and may not reflect all functionalities of this module. For download, source code and so on you should refer to the dedicated **PSWriteColor **module page. After reading this one… of course! It contains useful information, *examples *and know-how.

💡 Example Description

Below you can find example of:

Adding multiple colors in easy way

Creating basic options menu with multiple colors

Adding tabs, spaces and rows

Saving text to log file (same text as on screen is written to log)

Write-Color console output demonstrating multicolored text, numbered menu options, and messages that are also written to a log file.

This log file also gets created:

Notepad window showing the testing.txt log file created by Write-Color with timestamped messages copied from the console output.

💡 Basic examples for PSWriteColor

Import-Module PSWriteColor

Write-Color -Text "Red ", "Green ", "Yellow " -Color Red,Green,Yellow

Write-Color -Text "This is text in Green ",
                "followed by red ",
                "and then we have Magenta... ",
                "isn't it fun? ",
                "Here goes DarkCyan" -Color Green,Red,Magenta,White,DarkCyan

Write-Color -Text "This is text in Green ",
                "followed by red ",
                "and then we have Magenta... ",
                "isn't it fun? ",
                "Here goes DarkCyan" -Color Green,Red,Magenta,White,DarkCyan -StartTab 3 -LinesBefore 1 -LinesAfter 1

Write-Color "1. ", "Option 1" -Color Yellow, Green
Write-Color "2. ", "Option 2" -Color Yellow, Green
Write-Color "3. ", "Option 3" -Color Yellow, Green
Write-Color "4. ", "Option 4" -Color Yellow, Green
Write-Color "9. ", "Press 9 to exit" -Color Yellow, Gray -LinesBefore 1

Write-Color -LinesBefore 2 -Text "This little ","message is ", "written to log ", "file as well." `
            -Color Yellow, White, Green, Red, Red -LogFile "C:\testing.txt" -TimeFormat "yyyy-MM-dd HH:mm:ss"
Write-Color -Text "This can get ","handy if ", "want to display things, and log actions to file ", "at the same time." `
            -Color Yellow, White, Green, Red, Red -LogFile "C:\testing.txt"