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.
Using alias | sls -All "Get-"
. No result, because sls
uses toString
which is only the name column:
alias | Out-String | sls -All "Get-"
. Only highlightsalias | Where-Object {$_.Definition -like "*Get-Alias*"}
. A lot to write and requires knowing the column where the text is.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.Select-String
. Very inpractical....
Can someone help me with this problem?
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-"