PowerShell

Write-Color is now published as PowerShell Module

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:

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

This post was last modified on 10 czerwca, 2018 13:23

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

5 dni ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

4 miesiące ago

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

8 miesięcy ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

1 rok ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

1 rok ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

1 rok ago