In bash, if I do the following, I will get all the environment variables with wd
in them.
env | grep "wd"
Now, in Powershell, I know I could do
get-childitem env:wd*
But I want to pipe to select-string as a more generic approach, in order to filter what's coming in from its pipe, no matter what is to the left of the pipe. Just like grep.
This doesn't filter anything, I get all environment variables.
get-childitem env: | out-string | select-string -Pattern wd
And this gets me nothing:
get-childitem env: | select-string -Pattern "wd"
I know I could use the following, and it is actually a better match if I filter only on the environment variable's name. But what if I want a quick and dirty filter a la grep? And especially, without knowing about the attributes of what's coming in from the pipe.
get-childitem env: | where-object {$_.Name -like "wd*"}
i.e. is there a Powershelll equivalent to grep usable in a pipe context, not just in the context of file searches, which select-string
seems to cover well.
Out-String -Stream
get-childitem env: | Out-String -Stream | select-string -Pattern wd
was just the ticket. Thx! I dunno if you care, but I'll definitely accept it if you post it as an answer.