Monday, December 14, 2015

Format table row colors Inovation Powershell

This is my second post to earlier Format table color style odd even rows Powershell, I am eager to update it because if you see that post comments, one of the comment is from Jeffrey Snover (Father of Powershell), and he suggested some changes. (Even I am agree the output of earlier script Format-oddeven are not eyes friendly, but it was written in hurry).

Before giving the link and screenshot I would like to thanks Jim Nelson aka midnightfreddie http://midnightfreddie.com/. He worked on the script and Improvised it. (Yesterday I had Reddit it) I loved the way he used Indexing to change color of rows after every 3 lines, really brilliant use, and the second he solved my $input problem, so I don't have store information in $processData variable, It is nice learning.

#############################################
# Adapted from http://kunaludapi.blogspot.com/2015/12/format-table-color-style-odd-even-rows.html

function Format-RowColors {
    param (
        $RowsPerGroup = 3
    )
    begin {
        $Number = 0
        $ConsoleBack = [System.Console]::BackgroundColor
        $ConsoleFore = [System.Console]::ForegroundColor
        $RowColors = @(
            @{
                Back = "DarkGray"
                Fore = "Black"
            },
            @{
                Back = $ConsoleBack
                Fore = $ConsoleFore
            }
        )
    }
    process {
        $Number += 1
        # $Index will be either 0 or 1 and used to pick colors from $RowColors
        $Index = [Math]::Floor($Number / $RowsPerGroup) % 2
        [System.Console]::BackgroundColor = $RowColors[$Index].Back
        [System.Console]::ForegroundColor = $RowColors[$Index].Fore
        $_
    }
    end {
        [System.Console]::BackgroundColor = $ConsoleBack
        [System.Console]::ForegroundColor = $ConsoleFore
    }
<#
.Synopsis
Format table output row odd even colors.
.Example
Get-Service | Format-OddEven
.Notes
    NAME:  Format-OddEven
    AUTHOR: Kunal Udapi
    LASTEDIT: 10 Decemeber 2015
    KEYWORDS: Format Table color
.Link
Check Online version: Http://kunaludapi.blogspot.com
#>
} #function Format-OddEven
#############################################

Recently I received email from  
Post a Comment