Issue
Problem
I'm trying to find a way to find a string in a object list, like the result of Get-Alias
. My problem is that all solutions are either way too long to be practical to use or do not result in the behavior I need.
What I've tried so far:
Using alias | sls -All "Get-"
. No result, because sls
uses toString
which is only the name column:
- Using
alias | Out-String | sls -All "Get-"
. Only highlights
- Using
alias | Where-Object {$_.Definition -like "*Get-Alias*"}
. A lot to write and requires knowing the column where the text is.
- Using
alias | findstr "Get-"
. Works, but requires the use of a legacy executable that is not available on all PowerShell Core supported platforms. I want the code to work on all platforms without switches.
- Write to a file and then pipe that to
Select-String
. Very inpractical.
...
Can someone help me with this problem?
Solution
You want to grep the objects as you see them displayed on your console, your first example using Out-String
was going in the right direction except you were missing the -Stream
switch:
alias | Out-String -Stream | sls -All "Get-"
Or if you want to have it shorter, you can use the built-in wrapper oss
:
alias | oss | sls -All "Get-"
Answered By - Santiago Squarzon Answer Checked By - Willingham (WPSolving Volunteer)