Scroll Top
Evotec Services sp. z o.o., ul. Drozdów 6, Mikołów, 43-190, Poland

Write-Color is now published as PowerShell Module

img_5af03bf7bdf4f

As I tend to use more and more Write-Color every day for different projects I decided it's time to publish it as a module for easy usage. At the same time I get pointed that Write-Host which is heavily utilized by Write-Color is considered harmful as stated by Jeffrey Snover. And since it's THE Jeffrey Snover (Jeffrey Snover is a Microsoft Technical Fellow, PowerShell Chief Architect, and the Chief Architect for the Azure Infrastructure and Management group which includes Azure Stack, System Center and Operations Management Suite. Snover is the inventor of Windows PowerShell, an object-based distributed automation engine, scripting language, and command line shell and was the chief architect for Windows Server) so essentially I should care. And I do. I do understand his points.

But the thing is, and he states that clearly that for most of the use cases Write-Host will be wrong. But for some … perfectly fine! So use Write-Color with that in mind.

PSWriteColor Information
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 informationexamples and know-how.
Changelog / Version Information for newest 0.5 version
    [accordionitem] added backgroundcolor added aliases T/B/C to shorter code added alias to function (can be used with “WC”) fixes to module publishing [/accordionitem] [accordionitem] published as module fixed small issues [/accordionitem]
Basic examples for PSWriteColor

Basic functionality of this module is to create easy to use colorized output. You can also use it as standard Write-Host replacement.

Write-Host 'This is a test'
Write-Color 'This is a test'

But where it shines a lot…

Import-Module PSWriteColor

$line = '========================================================='

do {
    Clear-Host
    Write-Color $line -LinesBefore 1
    Write-Color 'ACTIVE DIRECTORY Domain Services Section' -C Green -StartTab 1
    Write-Color $line
    Write-Color ' 1', ' - ', 'List of Domain Controller and FSMO Roles' -C Yellow, White, Green
    Write-Color ' 2', ' - ', 'Domain Main Configuration' -C Yellow, White, Green
    Write-Color ' 3', ' - ', 'Forest Main Configuration' -C Yellow, White, Green
    Write-Color ' 4', ' - ', 'List all Windows Clients' -C Yellow, White, Green
    Write-Color ' 5', ' - ', 'List all Windows Server' -C Yellow, White, Green
    Write-Color ' 6', ' - ', 'List all Computer (sort by operatingsystem)' -C Yellow, White, Green
    Write-Color ' 7', ' - ', 'Run systeminfo on remote computers' -C Yellow, White, Green
    Write-Color ' 8', ' - ', 'List Domain Admins' -C Yellow, White, Green
    Write-Color ' 9', ' - ', 'Enabled Optional Features' -C Yellow, White, Green
    Write-Color '10', ' - ', 'List of Active GPOs' -C Yellow, White, Green
    Write-Color '11', ' - ', 'Default Password Policy Settings' -C Yellow, White, Green
    Write-Color '12', ' - ', 'Active Directory Sites' -C Yellow, White, Green
    Write-Color '13', ' - ', 'Users Last Logon' -C Yellow, White, Green
    Write-Color '14', ' - ', 'List all Users (enabled)' -C Yellow, White, Green
    Write-Color '15', ' - ', 'List User Details' -C Yellow, White, Green
    Write-Color '16', ' - ', 'List all Groups' -C Yellow, White, Green
    Write-Color '17', ' - ', 'List Group Memberships' -C Yellow, White, Green
    Write-Color '18', ' - ', 'Send message to users Desktop' -C Yellow, White, Green
    Write-Color '19', ' - ', 'Get Logged on User' -C Yellow, White, Green
    Write-Color ' 0', ' - ', 'Quit' -C Yellow, White, Green -LinesAfter 1
    Write-Color $line

    $input = Read-Host 'Select'

    Switch ($input) {
        0 { Exit }
        default {
            Write-Color 'Not implemented...', ' Press any key to continue!' -Color Red, Yellow -LinesBefore 1
            [void][System.Console]::ReadKey($true)
        }
    }
} while ($input -ne '0')

The results are as below:

PSWriteColor Example

For more information, usage examples and details visit dedicated PSWriteColor dedicated to this module. 

Posty powiązane