# Change the background and foreground colors on only one table entry

**URL:** <https://forums.powershell.org/t/change-the-background-and-foreground-colors-on-only-one-table-entry/11087>\
**Category:** PowerShell Help\
**Created:** [August 3, 2018, 12:49pm UTC](https://forums.powershell.org/t/change-the-background-and-foreground-colors-on-only-one-table-entry/11087 "2018-08-03T12:49:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [August 3, 2018, 12:49pm UTC](https://forums.powershell.org/t/change-the-background-and-foreground-colors-on-only-one-table-entry/11087/1 "2018-08-03T12:49:18Z")

</div>

Hi,

I am looking to change the background and foreground colors of only specific table entries, based on their value. What I am finding so far is that it changes the colors for everything. Here is what I have so far:

```
foreach($displayname in $InputObject){
     [pscustomobject]@{
         "Group Name" = $InputObject.displayname
         "Members" = if((($InputObject.members).count) -gt ((Get-UnifiedGroupLinks "gr-$($InputObject.displayname)" -LinkType members | select name).count))
          {
             $bc = (Get-Host).UI.RawUI
             $Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'yellow')
             write-output ($InputObject.members).count
             $host.ui.RawUI.BackgroundColor = $bc
             }
             else{
                   ($InputObject.members).count
                   }
         "Prod Group" = Get-UnifiedGroup "gr-$($InputObject.displayname)" | select -ExpandProperty displayname
         "Prod Members" = (Get-UnifiedGroupLinks "gr-$($InputObject.displayname)" -LinkType members | select name).count
}
```

So ideally, with the following output:

```
Group Name Members Prod Group Prod Members 
---------- ------- ---------- ------------ 
testgroup1 5 gr-testgroup1 5                                    
testgroup2 5 gr-testgroup2 4
```

The 5 in testgroup2 only would be changed, but the rest would be standard colors. With the code above, all the text changes.

Thanks for your consideration.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [August 3, 2018, 1:25pm UTC](https://forums.powershell.org/t/change-the-background-and-foreground-colors-on-only-one-table-entry/11087/2 "2018-08-03T13:25:09Z")

</div>

Manipulating colors in the shell are limited. $host is the host, the entire shell you are in. There is also:

```
PS C:\Users\Rob> Write-Host "This is a red string" -ForegroundColor Red
This is a red string
```

If you are wanting to change the colors of cells or rows, you’re better off working in HTML as your output where you can do just about anything that you want.

> **[Change Cell Color in HTML Table with PowerShell - Set-CellColor - Script...](https://community.spiceworks.com/scripts/show/2450-change-cell-color-in-html-table-with-powershell-set-cellcolor)**
>
> Another advanced function similar to the ConvertTo-AdvHTML function I recently released here: http://community.spiceworks.com/scripts/show/2448-create-advanced-html-table

There is also a free e-book on ‘ **Creating HTML Reports in PowerShell** ’ in the ebooks link above

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [August 3, 2018, 4:28pm UTC](https://forums.powershell.org/t/change-the-background-and-foreground-colors-on-only-one-table-entry/11087/3 "2018-08-03T16:28:36Z")

</div>

It is possible colorize console output. I do this regularly. Yet, understand that different environments can cause challenges.

Format the output table colors in PowerShell host with/without conditional colorful formatting.

> 'gallery.technet.microsoft.com/scriptcenter/Format-Table-Colors-in-e0a4beac'

and this…

> 'bgreco.net/powershell/format-color'

It’s also been asked for via uservoice on the MS PS Github as a native thing.

> 'github.com/PowerShell/PowerShell/issues/3886'

See also this discussion which also points to the above.

> 'stackoverflow.com/questions/20705102/how-to-colorise-powershell-output-of-format-table'

However, going the HTML route, be sure to look at the ‘EnhancedHTML module’ to help you out with this use case.

> 'powershellgallery.com/packages/EnhancedHTML2/2.1'

See this thread as well…

> 'powershell.org/forums/topic/conditional-formatting-in-psobject-output'

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/change-the-background-and-foreground-colors-on-only-one-table-entry/11087/4 "2024-05-16T20:34:38Z")

</div>


