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

  • SEARCH
  • Home
  • 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 6547465
In Process

The Archive Base Latest Questions

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

Let’s say I have the results of a call to Select-String in a variable

  • 0

Let’s say I have the results of a call to Select-String in a variable $mat, parsing a regular expression from file contents:

$mat = cat errors.txt | Select-String "'(?<code>\w+)'.+ID (?<id>[^:]+)" 

According to the output of $mat | Get-Member the result contains a Matches property of type Match[].

When I execute the following I get all the matches of my regular expression output:

PS > $mat | Select-Object -Property Matches

Matches                                                                                                                                                                              
-------                                                                                                                                                                              
{'ACCFWD', ID 16}                                                                                                                                                                    
{'EQASIAN', ID 448}                   
    

Why doesn’t this next block of code using foreach to select the Matches have the same output:

    PS > $mat | ForEach { $_.Matches } 


Groups   : {'ACCFWD', ID 16, ACCFWD, 16}
Success  : True
Captures : {'ACCFWD', ID 16}
Index    : 20
Length   : 15
Value    : 'ACCFWD', ID 16

Groups   : {'EQASIAN', ID 448, EQASIAN, 448}
Success  : True
Captures : {'EQASIAN', ID 448}
Index    : 20
Length   : 17
Value    : 'EQASIAN', ID 448
  • 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:50:04+00:00Added an answer on May 25, 2026 at 11:50 am

    When displaying properties, PowerShell auto-formats the properties of types that do not have a display format defined in a *.format.ps1xml file as a table for up to 4 properties. 5 or more properties displays as a list. When you select the Matches property with Select-Object, you are selecting a single property of the Microsoft.PowerShell.Commands.MatchInfo object. With Foreach-Object you are displaying all of the properties for a System.Text.RegularExpressions.Match object.

    Using Select-Object -ExpandProperty Matches will cause the output to look the same as the Foreach because it will output RegularExpressions.Match objects.

    If you place Get-Member after both of your examples that produce output you will see that they output different types of objects.

    Edit: Here is an explanation of the formatting that happens for each command.

    cat errors.txt | Select-String "'(?<code>\w+)'.+ID (?<id>[^:]+)"
    

    The output of Select-String is a Microsoft.PowerShell.Commands.MatchInfo object which has 8 properties. These properties are not displayed by default because the display format for MatchInfo is defined in PowerShellCore.format.ps1xml to show the result of MatchInfo‘s ToString() method.

    $mat | Select-Object -Property Matches
    

    In this case, the output of Select-Object is a custom Selected.Microsoft.PowerShell.Commands.MatchInfo object with the Matches property that was copied from the MatchInfo object. Since there is no default display format defined for the Selected.Microsoft.PowerShell.Commands.MatchInfo type, PowerShell auto formats it as a table since it has less than 5 properties (In this case Matches is the only property).

    $mat | ForEach { $_.Matches } 
    

    In the Foreach-Object ScriptBlock, the Matches property of the MatchInfo object is being output. The Matches property is a System.Text.RegularExpressions.Match which has 6 properties. Since there is no default display format defined for the System.Text.RegularExpressions.Match type, the Match objects are displayed as a list because there are more than 4 properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have this string which I want to put in a multidimensional
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and

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.