Split Select-String

13,807

The string value of the matched line is in the Line property of the MatchInfo object.

$foo.Line.split()
Share:
13,807
Zombo
Author by

Zombo

Hello world

Updated on August 04, 2022

Comments

  • Zombo
    Zombo almost 2 years

    Given this variable

    $foo = help | Select-String powershell
    

    Trying a split will fail

    PS > $foo.split()
    Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo]
    does not contain a method named 'split'.
    At line:1 char:1
    + $foo.split()
    + ~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound
    

    How can I split this variable?

  • Keith Hill
    Keith Hill almost 10 years
    While this works, it is not exactly embracing the nature of PowerShell i.e. it outputs objects not merely text. :-)