`Select-String` should have a `-AsPSObject` switch returning named groups as properties of an object
See original GitHub issueSummary of the new feature / enhancement
Currently, if you run something like:
PS /Users/steve/repos/PowerShell> ls -l *.md | select-string "(?<mode>.*?)\s+(?<hardlinks>[0-9]+)\s+(?<owner>\w+)\s+(?<group>\w+)\s+(?<size>[0-9]+)\s+(?<date>\w+\s[0-9]+\s[0-9:]+)\s+(?<filename>.+)"
-rw-r--r-- 1 steve staff 5122 Oct 24 08:37 ADOPTERS.md
-rw-r--r-- 1 steve staff 20383 Oct 27 09:33 README.md
select-string
just highlights the matches (imagine the text above highlighted). However, it would be useful to have a -AsPSObject
switch so that if there are named groups, those becomes properties of an object instance:
PS /Users/steve/repos/PowerShell> ls -l *.md | select-string "(?<mode>.*?)\s+(?<hardlinks>[0-9]+)\s+(?<owner>\w+)\s+(?<group>\w+)\s+(?<size>[0-9]+)\s+(?<date>\w+\s[0-9]+\s[0-9:]+)\s+(?<filename>.+)"
mode hardlinks owner group size date filename
---- --------- ----- ----- ---- ---- --------
-rw-r--r-- 1 steve staff 20383 Oct 27 09:33 README.md
-rw-r--r-- 1 steve staff 20383 Oct 27 09:33 ADOPTERS.md
Proposed technical implementation details (optional)
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to select a substring in select/group command
Just add another calculated property to the code you have to get the array of user objects: $ADUsers = foreach ($OU in $OUs)...
Read more >Select-Object (Microsoft.PowerShell.Utility)
The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of...
Read more >Everything you wanted to know about PSCustomObject
PSCustomObject is a great tool to add into your PowerShell tool belt. ... Sometimes you need a list of all the property names...
Read more >James O'Neill's Blog | Page 2
If you want the original object and its properties, they are there, untouched. They are available for a Select-Object or Format-List command to ......
Read more >PowerShellCookbook.psm1 1.2
Store the property names and identifiers for all of the shell ## properties $itemProperties = @{} ## Get the file from the input...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I like this idea. Someone is bound to ask “does this belong in
select-string
?” and I think the answer is “yes, it does” 😃New-RegexSelection
perhaps? Pretty much everyNew-*
command outputs a PSObject, and the command could have more similarities to the C# Regex method beyond just the pattern, like having parameters for the various RegexOptions. You could even pair it with aNew-RegexPattern
command for compiled regex patterns, e.g.: