1

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:

enter image description here


  1. Using alias | Out-String | sls -All "Get-". Only highlights

enter image description here


  1. Using alias | Where-Object {$_.Definition -like "*Get-Alias*"}. A lot to write and requires knowing the column where the text is.

enter image description here


  1. 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.

enter image description here


  1. Write to a file and then pipe that to Select-String. Very inpractical.

...


Can someone help me with this problem?

2
  • 1
    alias | oss | sls -All "Get-" Commented Dec 15, 2022 at 16:57
  • 1
    Posting images of technical information like code or console commands and output, instead of formatted text, is the fastest way I've seen here other than spam for a question to be downvoted and then closed or ignored. Commented Dec 15, 2022 at 17:32

1 Answer 1

4

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-"
Sign up to request clarification or add additional context in comments.

9 Comments

Off topic, but it's funny where you placed your winter hat haha
@AbrahamZinala LOL not sure where else it could go :D
It's just funny seeing a fish with one xD
Nice; Worth pointing out that that oss arguably shouldn't be necessary, and that Select-String should by default use the richly formatted string representation rather than the .ToString() value for non-string input objects, as suggested in GitHub issue #10726.
@mklement0 Thanks for pointing to that issue. It has some great suggestions :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.