I wrote some powershell code to do a specific task, and am interesting if
people can make it more elegant, or more "powershell"ish..
the context is i want to search through recursive directories on a webserver
look for files of a certian types (i.e .cfm .htm etc), then give a list of
files that contain a certian text in it.. giving a table with 3 columns, one
with the filename, the next with the line number , and the third the line
that has that text..
this is how i did it:
ls "\\somepath\wwwroot\" -re |
where { ".cfm",".htm",".asp",".html" -eq [system.IO.Path]::GetExtension($_
) } |
% { $linenum = 0; $temp = $_ ; $_} | get-Content |
Where-Object {$_ -match "www.whatever.org" } |
% {$res = 1 |Select-Object "name", "contentline", "linenum"; $res.Name =
$temp.name;$res.contentline = $_ ; $res.linenum = $linenum++ ; $res}
How would you do it?


