Did anyone think of formatting the output table as result of array of Objects/PSObjects on PowerShell host window with more fancy coloring? I wonder if any imagine if we can change the fore color or the back color of the headers rather than the body (rows) colors? What about formatting the table to have the odd rows with different fore/back colors rather than the even ones? What about putting different separator line for the header the dashed one? Or, what about just remove it, or color it with different fore/back color? What about putting separators between rows? And what if we can put those separators with different fore/back colors? What about presenting the values for specific columns/properties with different fore/back colors? What about some conditional formatting such as color specific values/cells when the values matches specific queries? Or what about color some values based on some complicated composite queries applies on multiple properties?

I had built my crazy PowerShell function “Write-PSObject” (pipeline supported) which can achieve all the imaginations and so much more with combination of over than 30 parameters which they can be used together or separately wisely to format your results with more fancy meaningful colors (fore/back).

The array of values validations way which must be provided with one of the three valid set "Exact", "Match" or "Query".

N/A

N/A

If this parameter not provided, the conditional formatting will not be functional and all the tailed parameters will be ignored. This must be tailed with the following parameters to be functional: "Column", "Value" and one or more of the following parameters: "ValueForeColor", "ValueBackColor", "RowForeColor" and/or "RowBackColor".

N/A

03

FormatTableColor

FTC, FT, F

Switch

False

If specified, lines will be formatted with specified fore/back colors based on the sequence.

User can define specific fore or/and back color for odd lines in sequence, and different fore or/and back colors for even lines.

N/A

N/A

User needs to use one or more of the following parameters with this switch in order to make it functional:

The list of the names of columns/properties which hold the value(s) to be validated to apply the table formatting.

*

N/A

This parameter can provided as one string or array of them which must match the same count of the "Value" parameter or the script will be terminated (If the "$IgnoreErrors" switch is provided, the function will not be terminated, but the formatting will not be functional). If the parameter "MatchMethod" is not provided, this column and all the other relative ones will be ignored and the whole conditional formatting will not be functional. The "*" is referring to all the columns/properties within the table/PSObject(s). If the "*" is provided as a name of column/property, that means the same condition defined by the "MatchMethod" and "Value" parameters will be applied on all the columns/properties. For example, you can just mention "*" as column/property name to color all the "False" values for any column/property withforecolor "Red" and/or backcolor "Black".

MatchMethod

05

Value

V

String[]

False

The value validation way which must be matching with one of the following three valid set provided by the parameter "MatchMethod" (all case insensitive):

1. Exact ---» The provided value must match exactly with the inputs.

Ex1: -Value "True"

Ex2: -Value $True

Ex3: -Value 4

Ex4: -Value "Ahmad", 4, "True", $False

2. Match ---» The provided value must match with part of the inputs.

Ex1: "Ahmad"

Ex2: -Value "Ah"

Ex3: -Value "ma"

Ex4: -Value "ad"

Ex5: -Value "X", "C123", "A"

3. Query ---» The provided value must match with the provided query which could contains various conditions on the same column.

This parameter can provided as one string value or array of them which must match the same count of the "Column" parameter or the script will be terminated (If the "$IgnoreErrors" switch is provided, the function will not be terminated, but the formatting will not be functional).

If the parameter "MatchMethod" is not provided, this column and all the other relative ones will be ignored and the whole conditional formatting will not be functional.

MatchMethod

Column

06

FormatTableColor

FTC, FT, F

Switch

False

If specified, lines will be formatted with specified fore/back colors based on the sequence. User can define specific fore or/and back color for odd lines in sequence, and different fore or/and back colors for even lines.

N/A

N/A

User needs to use one ore more of the following parameters with this switch in order to make it functional: "OddLineForeColor", "OddLineBackColor", "EvenLineForeColor" and/or "EvenLineBackColor"

N/A

07

ValueForeColor

VFC

ConsoleColor[]

False

Used to define the forecolor of the values that match the specified condition.

N/A

Red, Black, Blue, White, etc.

This parameter is function only when the following parameters are provided "MatchMethod" “Column” and “Value ”.

MatchMethod

Column

Value

08

ValueBackColor

VBC

ConsoleColor[]

False

Used to define the back color of the values that match the specified condition.

N/A

Red, Black, Blue, White, etc.

This parameter is function only when the following parameters are provided "MatchMethod" “Column” and “Value”.

MatchMethod Column Value

09

RowForeColor

RFC

ConsoleColor

False

Used to define the forecolor of the whole line/row that when of its values match the specified condition(s).

With another meaning, if no values inside that row/line (single PSObject) matches any provided condition, this parameter will be ignored.

N/A

Red, Black, Blue, White, etc.

If the "ValueForeColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s).

The "FlagsForeColor " of the flagged columns would override it.

MatchMethod

Column

Value

10

RowBackColor

RBC

ConsoleColor

False

Used to define the back color of the whole line/row that any of its values match the specified condition(s). With another meaning, if no values inside that row/line (single PSObject) matches any provided condition, this parameter will be ignored.

N/A

Red, Black, Blue, White, etc.

This parameter is function only when the "MatchMethod" parameter is provided. If the "ValueBackColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s). The "FlagsBackColor" of the flagged columns would override it.

MatchMethod Column Value

11

OddLineForeColor

OLFC

ConsoleColor

False

Used to define the forecolor of the whole line/row that with an odd sequence of the whole rows starting from the first row of values.

Example, you can provide that parameter with the forecolor of the rows positions 1, 3, 5, 7, etc.

The default forecolor of the host.

Red, Black, Blue, White, etc.

This parameter is function only when the "FormatTableColor" parameter is provided.

It can work with or without the other relative odd/even fore/back colors.

If the "ValueForeColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s).

If the "RowForeColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s).

The "FlagsForeColor " of the flagged columns would override it.

FormatTableColor

12

OddLineBackColor

OLBC

ConsoleColor

False

Used to define the back color of the whole line/row that with an odd sequence of the whole rows starting from the first row of values. Example, you can provide that parameter with the back color of the rows number 1, 3, 5, 7, etc.

The default back color of the host.

Red, Black, Blue, White, etc.

This parameter is function only when the "FormatTableColor" parameter is provided. It can work with or without the other relative odd/even fore/back colors. If the "ValueBackColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s). If the "RowBackColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s). The "FlagsBackColor" of the flagged columns would override it.

FormatTableColor

13

EvenLineForeColor

ELFC

ConsoleColor

False

Used to define the forecolor of the whole line/row that with an even sequence of the whole rows starting from the second row of values.

Example, you can provide that parameter with the forecolor of the rows number 2, 4, 6, 8, etc.

The default forecolor of the host.

Red, Black, Blue, White, etc.

This parameter is function only when the "FormatTableColor" parameter is provided.

It can work with or without the other relative odd/even fore/back colors.

If the "ValueForeColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s).

If the "RowForeColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s).

The "FlagsForeColor " of the flagged columns would override it.

FormatTableColor

14

EvenLineBackColor

ELBC

ConsoleColor

False

Used to define the back color of the whole line/row that with an odd sequence of the whole rows starting from the second row of values. Example, you can provide that parameter with the back color of the rows number 2, 4, 6, 8, etc.

The default back color of the host.

Red, Black, Blue, White, etc.

This parameter is function only when the "FormatTableColor" parameter is provided. It can work with or without the other relative odd/even fore/back colors. If the "ValueBackColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s). If the "RowBackColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s). The "FlagsBackColor" of the flagged columns would override it.

FormatTableColor

15

HeadersForeColor

HFC

ConsoleColor

False

Used to define the forecolor of the whole two headers lines/rows.

The first header row/line which describes the names of the columns/properties.

While, the second header row/line is the underlines dashes characters which separate the header names than the rows' values.

Example, When get the results of the function "Get-ChildItem -Path C:\ | FT -Al;", the output would be something like the following:

ModeLastWriteTime Length Name# First header line.

----------------- ------ ---- # Second header line.

The default forecolor of the host.

Red, Black, Blue, White, etc.

This parameter is not dependent on any other parameters or conditions.

N/A

16

HeadersBackColor

HBC

ConsoleColor

False

Used to define the back color of the whole two headers lines/rows. The first header row/line which describes the names of the columns/properties. While, the second header row/line is the underlines dashes characters which separate the header names than the rows' values. Example, When get the results of the function "Get-ChildItem -Path C:\ | FT -Al;", the output would be something like the following: ModeLastWriteTime Length Name# First header line. ----------------- ------ ----# Second header line.

The default back color of the host.

Red, Black, Blue, White, etc.

This parameter is not dependent on any other parameters or conditions.

N/A

17

BodyForeColor

BFC

ConsoleColor

False

Used to define the forecolor of the whole lines/rows values.

The default forecolor of the host.

Red, Black, Blue, White, etc.

This parameter is not dependent on any other parameters or conditions.

If the "ValueForeColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s).

If the "RowForeColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s).

If the "OddLineForeColor" and /or "EvenLineForeColor" parameter(s) are provided, they would override it.

The "FlagsForeColor " of the flagged columns would override it.

N/A

18

BodyBackColor

BBC

ConsoleColor

False

Used to define the back color of the whole lines/rows values.

The default back color of the host.

Red, Black, Blue, White, etc.

This parameter is not dependent on any other parameters or conditions. If the "ValueBackColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s). If the "RowBackColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s). If the "OddLineBackColor" and /or "EvenLineBackColor" parameter(s) are provided, they would override it. The "FlagsBackColor" of the flagged columns would override it.

N/A

19

ColoredColumns

CC

String[]

False

Define the columns/properties to have their values colored without conditions.

N/A

"CPU", "Memory", "SN"

This parameter is not dependent on any other parameters or conditions.

N/A

20

ColumnForeColor

CFC

ConsoleColor[]

False

Used to define the forecolor of values the specified "ColoredColumns".

N/A

Red, Black, Blue, White, etc.

This parameter is function only when the "ColoredColumns" parameter is provided. If the "ValueForeColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s). If the "RowForeColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s). If the "OddLineForeColor" and /or "EvenLineForeColor" parameter(s) are provided, they would override it. The "FlagsForeColor" of the flagged columns would override it.

ColoredColumns

21

ColumnBackColor

CBC

ConsoleColor[]

False

Used to define the back color of the whole lines/rows values.

N/A

Red, Black, Blue, White, etc.

This parameter is function only when the "ColoredColumns" parameter is provided.

If the "ValueBackColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s).

If the "RowBackColor" is provided, it could override the color of the whole line/row, if they match with specific provided condition(s).

If the "OddLineBackColor" and /or "EvenLineBackColor" parameter(s) are provided, they would override it.

The "FlagsBackColor" of the flagged columns would override it.

ColoredColumns

22

FlagColumns

FC

String[]

False

Define the columns/properties to have their values colored when any of the specified values match the specified condition(s).

N/A

"CPU", "Memory", "SN"

This parameter is function only when the following parameters are provided "MatchMethod" “Column” and “Value”.

MatchMethod Column Value

23

FlagsForeColor

FFC

ConsoleColor[]

False

Used to define the forecolor of the flagged columns/properties.

N/A

Red, Black, Blue, White, etc

This parameter is function only when the ""MatchMethod" “Column”, “Value” and "FlagColumns" parameters are provided.

If the "ValueForeColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s).

This would override the colors specified by the "RowBackColor", "OddLineFBackColor" and/or the "EvenLineBackColor " parameters.

MatchMethod

Column

Value

FlagColumns

24

FlagsBackColor

FBC

ConsoleColor[]

False

Used to define the back color of the whole lines/rows values.

The default back color of the host.

Red, Black, Blue, White, etc

This parameter is function only when the ""MatchMethod" “Column”, “Value” and "FlagColumns" parameters are provided. If the "ValueBackColor" is provided, it could override the colors of the matched properties values, if they match with specific provided condition(s). This would override the colors specified by the "RowForeColor", "OddLineForeColor" and/or the "EvenLineForeColor" parameters.

MatchMethod Column Value FlagColumns

25

InjectRowsSeparator

IRS

Switch

False

If specified, new lines would be injected between body rows/lines.

N/A

N/A

By default the new line separator would be just new line with null data as the default value of the "RowsSeparator " parameter is $null.

N/A

26

RowsSeparator

RS

String

False

Define the shape of the separator line/row between body rows/lines. The value could be one character such as "-", "==", etc., or mixed ones and the line would be trimmed by the maximum length of the body rows.

$null

"-", ".", "=", "|", "#", " ", etc.

This parameter is function only when the "InjectRowsSeparator" parameter is provided. If not specified, the new line separator would be just new line with null data.

InjectRowsSeparator

27

RowsSeparatorForeColor

RSFC

ConsoleColor

False

Used to define the forecolor of the separator rows/lines.

The default forecolor of the host.

Red, Black, Blue, White, etc.

his parameter is function only when the "InjectRowsSeparator" and "RowsSeparator " parameters are provided.

InjectRowsSeparator

RowsSeparator

28

RowsSeparatorBackColor

RSBC

ConsoleColor

False

Used to define the back color of the separator rows/lines.

The default back color of the host.

Red, Black, Blue, White, etc.

This parameter is function only when the "InjectRowsSeparator" and "RowsSeparator" parameters are provided.

InjectRowsSeparator RowsSeparator

29

RemoveHeadersSeparator

RHS

Switch

False

Neglect displaying the second header line "----" (the separator line between headers (columns/properties) names and the body rows/values.).

With another meaning, the values rows/lines would be printed directly after the columns/properties names line/row.

N/A

N/A

This parameter will not be functional if "BodyOnly " parameter is specified.

N/A

30

HeadersSeparator

HS

String

False

Define the shape of the separator header separator line "----" between the columns names and body rows. The value could be one character such as ".", "==", etc., or mixed ones and the line would be trimmed by the maximum length of the body rows.

"-"

".", "=", "|", "#", " ", etc.

This parameter will not be functional if any of the two parameters "BodyOnly" or "RemoveHeadersSeparator" is specified.

N/A

31

HeadersSeparatorForeColor

HSFC

ConsoleColor

False

Used to define the forecolor of the separator header separator line "----" between the columns names and body rows.

The default forecolor of the host.

Red, Black, Blue, White, etc.

This parameter will not be functional if any of the two parameters "BodyOnly" or "RemoveHeadersSeparator " is specified.

N/A

32

HeadersSeparatorBackColor

HSBC

ConsoleColor

False

Used to define the back color of the separator header separator line "----" between the columns names and body rows.

Red, Black, Blue, White, etc.

This parameter will not be functional if any of the two parameters "BodyOnly" or "RemoveHeadersSeparator" is specified.

N/A

33

BodyOnly

BO

Switch

False

If specified, only the body rows (values lines) will be displayed, and, the two headers lines will not be displayed.

N/A

N/A

This parameter is not dependent on any other parameters or conditions.

N/A

34

HeadersOnly

HO

Switch

False

If specified, only the two headers lines will be displayed, and, the body rows (values lines) will not be displayed.

N/A

N/A

This parameter is not dependent on any other parameters or conditions.

N/A

35

IgnoreErrors

IE

Switch

False

It would try to suppress and error/exception could be raised due to missing or non-matched parameters and continue displaying the rows.

N/A

N/A

This parameter is not dependent on any other parameters or conditions.

If one of the provided conditions which is provided by the combination of the properties "MatchMethod","Column", "Value" and/or "FlagColumns" and/or their relative properties was not well provided, or mismatching, the "MatchMethod " property would be ignored and the conditional formatting will not be functional.

N/A

36

HostWindowWidth

HWW

UInt16

False

Resize the host PowerShell window with a new specified width before presenting the data.

N/A

N/A

This parameter is not dependent on any other parameters or conditions. It would also resize the buffer width size with the same specified value if the current value is less than the new specified window width.

N/A

37

HostWindowHeight

HWH

UInt16

False

Resize the host PowerShell window with a new specified height before presenting the data.

N/A

N/A

This parameter is not dependent on any other parameters or conditions.

It would also resize the buffer height size with the same specified height if the current value is less than the new specified window height.

N/A

38

HostWindowForeColor

HWFC

ConsoleColor

False

Override the current forecolor of the host PowerShell with a new specified one before presenting the data.

N/A

N/A

This parameter is not dependent on any other parameters or conditions.

N/A

39

HostWindowBackColor

HWBC

ConsoleColor

False

Override the current background color of the host PowerShell with a new specified one before presenting

N/A

N/A

This parameter is not dependent on any other parameters or conditions.

Example 06

Display the input object as formatted table which displays each row/line in odd sequence (starting with the first body row) with "Cyan" forecolor.Also, display each row/line in even sequence (starting with the second body row) with "Yellow" Fore Color.

Example 07

Display the input object as formatted table which displays each row/line in odd sequence (starting with the first body row) with "DarkRed" background color.Also, display each row/line in even sequence (starting with the second body row) with "Blue" background color.

Example 08

Display the input object as formatted table which displays each row/line in odd sequence (starting with the first body row) with "Black" forecolor and White background color..Also, display each row/line in even sequence (starting with the second body row) with "Yellow" Fore Color and Blue background color.

Those samples were just few of what the function can do!You can mix many samples together by mixing the parameters to get more fancy colorful results.If those samples are not enough to help you to build your own color formatting, please check the parameters table above, or feel free to leave a message/comment for me, and I will reply as soon as possible.

Date: October, 22nd, 2017Update: Fixed a logical bug which could occur with results of two columns only.

Date: December, 21st, 2018Update:Fixed a regression bug when specifying the "-InjectRowsSeparator" parameter without specifying the value of the "-RowsSeparator" one.Fixed an intermittent bug when selecting one column only.Fixed a regression/intermittent bug which was causing displaying some random incomplete values strings.

Hi, usually we get this error when you try to run your code on the ISE. Nevertheless, this should have been handled already which could mean a bug in the script. Could you please support me with the line of code you used to check this? Also, could you confirm if you are using the ISE not the console?

The ISE doesn't have a default host environment foreground color or default background color, hence, I'm putting the default values of the PS Console instead.
If you tried to run the following commands in ISE, you will see that the default values are "-1":
(Get-Host).UI.RawUI.ForegroundColor
(Get-Host).UI.RawUI.BackgroundColor

To overcome this solution with the current version of my script, you can set the default colors on the ISE from "Tools>Options>Colors and Fonts".
Or, you can download the updated version from the following link and give it a try.
I would ask you a favor to give it a proper test; and then, send me your feedback before I upload it to my blog and to the MSDN repository:
ahmad.jempress.com/.../...-PSObject-2017-09-17.ps1

With this example the 8's are highlighted but the 16's are not. After some testing its only comparing the 2 vs the first number of the CPUCores. Since the 8 is greater then the 2 the does highlight however from the 16 only the 1 is being used so it does not get highlighted.
If the CPUCores would be something like 40 it would start to be highlighted again.

Another issue i do not understand.
I feel its reproducible using this code.
The first one the Id field looks right. In the second example the Id field is missing a character and is being evaluated incorrectly.

I think i have ran into another issue.
A way to repeat this is with the following commands.
Write-PSObject (Get-Process | Select-Object name, id)
Write-PSObject (Get-Process | Select-Object name, id) -MatchMethod query -Column Id -Value "'id' -GT 99" -ValueForeColor Red

You will notice the ID column of the first command works correctly. The second command has an odd space in the command and incorrect highlighting.

Somehow my first post on this disappeared.
Thanks for the great tool. Hope we can squash these bugs.

Thank you very much for your comments again.
First, let me just explain to you that your first or even second comment won't appear unless I manually approve them, which I did few minutes ago, so be patient please.

Thank you very much for your comment.
I had identified the bug and it happens with very rare situation that's why I didn't see it before although I had used the function in different scripts.
The bug requires revising to big parts of the code which would take time cause I need to work on it when I've free time.
Please bear with me until I resolve the bug and thanks for you for identifying it.