filter outputs using select-string pipes
By default Out-String
produce single string object, which contain all the output, so the following filter will select or discard all output as whole. You need to use -Stream
parameter of Out-String
cmdlet to produce separate string object for each output line.
Same answer, as a function and alias one can include in one's powershell profile:
function Find-Env-Variable (
[Parameter(Mandatory = $true, Position=0)]
[String]$Pattern){
get-childitem ENV: | Out-String -Stream | select-string -Pattern "$Pattern"
}
Set-Alias findenv Find-Env-Variable