Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6541611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:07:31+00:00 2026-05-25T11:07:31+00:00

Is it possible to color only certain words (not complete lines) for a powershell

  • 0

Is it possible to color only certain words (not complete lines) for a powershell output using format-table. For example, this script scans a folder recursively for a string and then output the result with format-table.

dir -r -i *.* | Select-String $args[0] |
format-table -Property @{label="Line #"; Expression={$_.LineNumber}; width=6},
Path, Line -wrap

It would be nice to be able to format the word we are searching for with a specific color, so that you can see exactly where it was found on the line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:07:32+00:00Added an answer on May 25, 2026 at 11:07 am

    You could pipe the table into Out-String, then write the string in parts using Write-Host with the -NoNewLine switch.

    Something like this:

    filter ColorWord {
        param(
            [string] $word,
            [string] $color
        )
        $line = $_
        $index = $line.IndexOf($word, [System.StringComparison]::InvariantCultureIgnoreCase)
        while($index -ge 0){
            Write-Host $line.Substring(0,$index) -NoNewline
            Write-Host $line.Substring($index, $word.Length) -NoNewline -ForegroundColor $color
            $used = $word.Length + $index
            $remain = $line.Length - $used
            $line = $line.Substring($used, $remain)
            $index = $line.IndexOf($word, [System.StringComparison]::InvariantCultureIgnoreCase)
        }
        Write-Host $line
    }
    
    Get-Process| Format-Table| Out-String| ColorWord -word 1 -color magenta
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to disable texture colors, and use only white as the color?
Is it possible to set the color of a single vertex using a GLSL
Is it possible to set background color for only (1/4)th portion of a View
I want to change only bottom border style. Is it possible? I know this
It seems I am not the only one complaining about this . The yellow/gold
Is it possible to change only the color of a single bar in a
Is it possible to export for example table, or ul tags with all children
In a .vimrc , is it possible to load a color scheme only if
This is plugin that I want, Eclipse Color Theme 0.9.1 http://marketplace.eclipse.org/content/eclipse-color-theme https://github.com/eclipse-color-theme/eclipse-color-theme I only
Possible Duplicate: How to represent 18bit color depth to 16bit color depth? I'm porting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.