I find out a possible method by "filter" and "alias" of PowerShell, when you want use grep in pipeline output(grep file should be similar):
first define a filter:
filter Filter-Object ([string]$pattern) {
Out-String -InputObject $_ -Stream | Select-String -Pattern "$pattern"
}
then define the alias:
New-Alias -Name grep -Value Filter-Object
final, put the former filter and alias in your profile:
$Home[My ]Documents\PowerShell\Microsoft.PowerShell_profile.ps1
Restart your PS, so you can use it:
alias | grep 'grep'
References
alias:
Set-Alias
here
New-Alias
here
Filter
(Special function) here
Profiles (just like .bashrc for bash): here
out-string
(this is the key) here:
in PowerShell Output is object-based here,so the key
is to convert object to string and grep the string.
Select-String
here:
Finds text in strings and files