Emulating Grep in Powershell

Emulating Grep in Powershell. The option presented is to perform a grep on several files.

For a search in one file, with results going to output.txt

select-string -pattern "{pattern}" -caseSensitive c:pathtofile.txt > output.txt

One note: The lines wrapped at the width of the command window, even when redirected to a file.

First pieces of code in PowerShell


$sw = new-object System.IO.StreamWriter(“c:ts.txt”)


$sw | get-member -memberType methods

For some reason, this method of invoking object methods is reminiscent of both Ruby and Smalltalk for me.

From the PowerShell team blog

PowerShell Team Blog blog entry on the Linux Magazine

Bash vs. Vista PowerShell from Linux Magazine

PowerShell Script Center