ahhh... missed that in your previous post. Well now that kinda changes everything. Get-content reads the whole file, into an array. Normally this isn't a problem. However in this case it is, because GC strips off the line breaks \r\n. Without those line breaks we can't do a blind match. Therefor my answer is null and void, well kinda... First your question.
I went to re-write this using foreach and -match, and then /\/\o\/\/ popped in my goggle reader. It seams your question caught the attention of the Powershell guy himself! http://thepowershellguy.com/blogs/posh/archive/2008/10/24/hey-powershell-guy-how-can-i-use-get-content-to-analyze-sql-server-logfile.aspx
Back to me... the problem is that [regex]::Match() matches against the whole string, and when you access the information from get-content without the pipeline. It reads the whole file in only this time there are no line breaks. See the problem here... the only way to perform a blind match in regex is with "." DOT. DOT essentially says match the next anything I don't care(with the only exception being line breaks). Therefore .+ DOT.PLUS will match anything to the end until it encounters a line break.
Why didn't I catch that before? That was due to an oversight on my part. When I tested that one liner I never used an actual file. Instead I simulated one...
$log = @"
2008-07-16 09:51:51.40 spid3 "OK"
2008-07-16 09:51:52.04 spid3 "OK"
2008-07-16 09:51:52.04 spid5 "OK"
2008-07-16 09:51:52.04 spid3 "OK"
2008-07-16 09:51:52.04 spid5 "ERROR:"
2008-07-16 09:51:52.04 spid3 "OK"
2008-07-16 09:51:52.04 spid5 "ERROR:"
2008-07-17 09:51:52.04 spid5 "ERROR:"
2008-07-17 09:51:52.04 spid3 "OK"
2008-07-18 09:51:52.04 spid5 "ERROR:"
2008-07-18 09:51:52.04 spid5 "OK"
2008-07-18 09:51:52.04 spid5 "ERROR:"
"@
[regex]::matches($log, '(\d{4}\-\d{2}\-\d{2})\s(\S+)\s(\S+)\s\"ERROR.+') | `
?{[datetime]$_.groups[ 1 ].value -gt ((get-date).addDays(-2))} | select value
The key there, LINE BREAKS! Now if you absolutely wanted/needed to you could reinsert those line breaks with the following.
$log = [string]::join([environment]::NewLine, (get-content err.txt))
Thanks for such an interesting question... had fun playing with that.
Now let me go type all this in my blog :)
~Glenn
UPDATE: I just re-read my post, and want to clarify something. The problem I ran into was in my implementation not regex itself. whether you use -match, [regex]::match(), etc they all use the same subsystem. They just maintain different use cases.